java - Can't convert byte to normal view -


I have a long value, which I want to change the OT byte array. I use this function

  public static byte [] verticalobetre (long value) {byte [] result = new byte [8]; For (int i = 0; i   

and looks like output data

  18 10010 -12 111111111111111111111111110100 88 1011000 83 1010011 0 0 0 0 0 0 0  < / Pre> 

I have too much 1 in the binary view of 12, and how can I get it?

  11110100    P> 

This is because Integer.toBinaryString (result [i]) converts your byte to int (32 bit), and also bytes -128 to 127, so more than 127 values ​​as negative numbers Shaya being; Therefore, your byte ends with a negative int. You can change this line to solve it:

  System.out.println (integer.binary string (result [i]) );   

For this one:

  System.out.println (integer. Binary string (result [i] & amp; 0xFF);    

Comments

Popular posts from this blog

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -