Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing the original byte  RSS feed

 
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?
 
Java Cowboy
Sheriff
Posts: 16083
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:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!