java - Parse binary string as byte in JavaScript -


Is

A binary string like "11100011" to me and I have to change it in a byte wish I have Java is a working example below:

  bytes B1 = (byte) integer. ParseInt ("11100011", 2); Println (b1);  

Here the output will be -29 . But if I wrote down some of the same code in JavaScript:

  parseInt ( '11100011', 2);  

I get an output of 227 .

Why should I write a JavaScript code to get the output similar to Java? As

Java bytes , two signatures, The one which is negative is the highest bit 1. Javascript is interpreting it as unsigned, so it is always positive.

Try it:

  var b1 = parseInt ( '11100011', 2); If (B1> 127) B1 - = 256;  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

c# - NewtonSoft JArray - how to select multiple elements with LINQ -

javascript - amcharts makechart not working -