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
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?
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
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