• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing the original byte  RSS feed

 
Khaled Za
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why when I do this:

I still get: 99 ... not the hex representation of the byte!!
Why is that?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are just printing the numerical value of the byte, which is printed in decimal by default. A byte is just like an int, but then 8 bits instead of 32 bits. Casting an int literal such as 99 to byte doesn't automatically make it print in hexadecimal representation.

If you want to print hexadecimal, use for example System.out.printf:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!