Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Byte Conversion  RSS feed

 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a byte array. Some values are negative due to overflow. (193-->-65)
How can I convert this -65 value to 193 without an if statement?
Thanks
Murat
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
byte b=-65;
System.out.println(b);
System.out.println(b & 0xFF); // <<<< the conversion.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all 193 is not -65 it is -63. And second, I don't know how you are going to distinguish between non-overflow negative values and overflow negative values in your array, unless you are certain that all the numbers in the array are positive (negative values always refer to overflow).
There is always the possibility that -65 is the overflow number for 193, 449, 705... etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!