• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integer.toHexString() on a negative value ?

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a program that generated a 20 byte SHA-1 hash value.
The values are in a byte array and I am trying to print them
out as hexadecimal string.
I am having problems printing out negative values.
e.g. byte b = (byte)0xff;
System.out.println( Integer.toHexString(b) );
produces fffffffd ?? Shouldn't I get back ff ?
Thanks
Pho
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the below from the api states exactly what is happening
toHexString
Creates a string representation of the integer argument as an unsigned integer in base 16.
The unsigned integer value is the argument plus 2^32 if the argument is negative; otherwise, it is equal to the argument.
Hope that helps, Tom
------------------
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic