Converting Base 64 to plain text using Javascript

When working on the Server in WebApiController, I have the following Byte array:

private Byte[] bytes = new Byte[21];

Once it is filled, it looks like this:

bytes = new byte{127,253,159,127,253,223,127,253,255,127,252,63,0,1,192,127,252,255,127,253,191};

I am aware that this will be a string representation:

111111101011111111111001111111101011111111111011111111101011111111111111111111100011111111111100000000001000000000000011111111100011111111111111111111101011111111111101

However, when receiving a response from the server on the client side, the array appears as:

f/2ff/3ff/3/f/w/AAHAf/z/f/2/

This is in base64 format. How can I convert this back to a string type equivalent to:

111111101011111111111001111111101011111111111011111111101011111111111111111111100011111111111100000000001000000000000011111111100011111111111111111111101011111111111101

Please assist me in finding a solution to this issue. Implementation in JS or AngularJS would be greatly appreciated.

Answer №1

This code snippet will help you to convert a byte array into a string with binary representation.

var byteArray = new byte[] {
    255, 127, 192, 63, 240, 15, 12, 9, 77, 33,
    200, 100, 150, 215, 180, 210 };

var binaryString = byteArray
    .Select(delegate(byte b)
        {
            int value = b;
            var strBinary = string.Empty;

            for (var i = 0; i < 8; i++, value /= 2)
                strBinary = (value % 2) + strBinary;

            return strBinary;
        })
    .Aggregate((acc, item) => acc + item);

Console.WriteLine(binaryString);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Explain and suggest the necessary parameters for a function

Is there a way to clearly describe the parameters required by my function and make them visible when I am typing my code? For instance, if we consider the ExpressJS render function below, it effectively shows what the callback expects and will return. In ...

The specified property type 'url' is not recognized on the provided 'Event' type

I came across the error message below [ts] Property type 'url' does not exist on type 'Event'. any This is the TypeScript (JavaScript) code snippet that I am using document.addEventListener("deviceready", onDeviceReady, false); ...

Error encountered when attempting to edit files using the Client.EditFiles method in the .NET API, caused by a revision

con.Client.EditFiles(foundFiles, new Options(EditFilesCmdFlags.None, changelist.Id, null)); Upon execution of the above line of code, an error message appears stating "A revision specification (# or @) cannot be used here." This error may be occurring due ...

Exploring the .map() Method in ReactJS

Would it be feasible to integrate another Postgres database table into the current mapping displayed in this code? It would be ideal if it could be done using some sort of array function. {items.map(item => ( <tr key={item.id}& ...

What is the importance of using a polyfill in Babel instead of automatically transpiling certain methods?

Recently, I have been diving into a course that delves into the use of babel in JavaScript. It was explained to me that babel, with the preset "env," is able to transpile newer versions of ES into ES5. However, I found myself facing a situation where the a ...

No cookie found in the system

Attempting to create an effect using bloom and shaders in post-processing. However, encountering an error in the console with a blank white screen. I have tried clearing cookies, caches, and even running this in incognito mode, but it's still not work ...

Converting a Class Component to a Functional Component: Step-by-Step Guide

Recently, I have been transitioning from working on class components to function components in React. However, I am facing some issues with my functional component code after converting it from a class component. In my functional component code, there is ...

Break down an array-like object with no duplicates

I'm currently learning about working with JavaScript arrays and have a question regarding creating new array objects by splitting an attribute of an existing object. I attempted using methods like .map and .flatMap, but the output I received consiste ...

Transform various tables enclosed in separate div elements into sortable and filterable tables

I'm encountering an issue with making multiple tables sortable and searchable on one page. Despite all the tables having the same class and ID, only the first table is responsive to sorting and searching. I've followed a tutorial that recommends ...

Struggling with an unspecified index in PHP

I've been struggling with this issue for days now. I can't seem to figure out why I keep getting an undefined index error in this code, and also why won't $text display anything when echoed? $http({ url: url, url2, method: "POST", dat ...

What is the best way to correlate two arrays of strings with one another?

I am working with two sets of data: First Set: let training = [ "Z1,1545 John Doe,P1", "Z2,2415 Shane Yu,P2" ]; Second Set: let skill = [ "P1, Shooting", "P2, Passing", ]; I need to combine both arrays bas ...

Using AngularJS and JavaScript, set the Submit button to be enabled only when the email input is valid and a value is selected in

I'm trying to create a form that includes an email input field and a drop-down list sourced from a database array. Initially, the submit button is disabled when the form loads. My goal is to figure out how to activate the submit button only when the ...

Rotating the model from its center after panning the model

Hey there! I've been tinkering around with Three.js and loading JSON models using JSONLoader. I also have TrackballControls.js set up for some basic interaction. However, I've noticed that the rotation behaves differently after moving (PAN) the o ...

How can I transform this statement into a higher-order function that offers a resource instead of using an object for initialization and destruction?

Starting with this code snippet: convert utilizes svgInjector to start and terminate a resource. export async function convert( serializedSvg: string, svgSourceId: string, containerId: string ): Promise<string> { const svgInjector = new SvgI ...

Ways to halt streaming without shutting down the Node.js server

I am currently facing an issue with closing a Twitter stream, as it causes my server to crash and requires a restart. Is there a way to close the stream without affecting the Nodejs (express) server? Here is the error message I am encountering: file:///mnt ...

Exploring the functionalities of Razor, Resharper, and Less within WebStorm

Can Jetbrains Webstorm be used to work with ReSharper, Less, and Razor? Are there any specific plugins recommended for this setup? Thank you ...

Guide on redirecting a webpage post form validation in JavaScript

I have a question about my JavaScript code. Even if validation fails, the contact us page still appears. How can I fix this issue? Appreciate any help. Thank you! (function () { window.addEventListener('load', function () { var forms = do ...

Transforming iframe programming into jquery scripting

Currently, I have implemented an Iframe loading the contents within every 5 seconds. It works well, however, there is a consistent blinking effect each time it loads which can be quite bothersome. I am looking to replace the iframe with a scrolling div so ...

Express.js along with Node.js is inefficient in delivering static files at a quicker pace

During the development of my current node project, I sometimes encounter a persistent hanging refresh issue. This occurs when the page fails to load and upon checking the network tab in Chrome, I notice that it gets stuck on static files. The type of stati ...

What is the best way to sort items in an array in React based on their length being below a specific number?

I am attempting to utilize the filter() method in order to filter out items from an array if the length of the array is below a certain amount, within the context of ReactJS. Unfortunately, I have not yet succeeded in achieving this. Sample Code: class T ...