wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes What's the difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

What's the difference

Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
0x45 in hexadecimal and just plain old 45 in hexadecimal?
Thanks in advance for your help.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
I'm not sure what you mean, Brian.
Java interprets the literal 0x45 as a hexadecimal value, equivalent to decimal 69, and furthermore, I believe, treats it as an int.
Java interprets the literal 45 as an int, equivalent to decimal 45.
Of course, hexadecimal 45 = hexadecimal 45, but Java will not treat a literal as a hexadecimal without the 0x (or 0X) prefix.
Art
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks. That really helped!
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Cool.
Art
Joseph Russell
Ranch Hand

Joined: Jan 08, 2001
Posts: 290
I'm fairly new to programming and so maybe this seems like a dumb question but I have yet to see a reason to convert hex to binary or decimal or vice-versa. What are some real life situations where this is needed?
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
The only answer there is - visual display. Hex A0, Dec 160 and Binary 10100000 are all the same value to the computer. However, 160 is the 'Hard Space' used in HTML and interperted as such in beowsers and html editors. All you see is a space. When we converted to jsp, this started throwing parse exceptions in TomCat. A HexEditor was used to find these and change them to Hex 20 or Dec 32 the actual space character.
Using a display program that will show you the binary equivelent to a number can be helpful in understand bit operations. Read Cat and Mouse Game with Bits pay attention to the Applet at the end


------------------
Hope This Helps
Carl Trusiak


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The binary conversions are needed if you are going to work with bit operators.
Course most of us don't want to, but if you work in MicroEdition for embedded chips (like for you thermostat, or your cell phone menu etc.) space is at a premium and they tend to use bit operators alot to save space. I'm sure they get to thinking in binary alot.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's the difference
 
Similar Threads
Another Ques from abhilash's site
shifting
fundamentals
Hexadecimal
Java Object Reference Variable Question