File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Hexadecimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Hexadecimal" Watch "Hexadecimal" New topic
Author

Hexadecimal

TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
Can you please explain to me why 0xFFFFFFFC = -4.0, and why 0xFFFFFFDF = -33 ? I am having difficulty learning hexadecimal, not to mention negative hexadecimal. Maybe you can recommend a good web site that explains it.
Thanks,
TM
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

the trick with hex is to turn into binary (which is actually easier to do than Decimal) -- and then figure out what that binary number is.
So... we've got these 2 numbers: 0xFFFFFFFC and 0xFFFFFFDF

So... now that I've done that one for ya -- can you figure out the other?
Grab a piece of scrap paper and count from 0-15 in binary and that will help you to convert the Hex digits to its binary equivalent.
[ August 19, 2003: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
That's a big help. I'm not sure if I have it 100% but that well get me going well on my way.
Thanks Alot,
TM
TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
Would you mind also explaining how you can go from decimal to hex? Specifically, take the number 1976, how do you come up the hex value?
Thanks,
TM
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Decimal to Hex is a little trickier..
You can check out this thread for some instruction about how:
http://www.coderanch.com/t/242789/java-programmer-SCJP/certification/Octal-hexadecimal-representation
BUT -- the good news is, converting Decimal -> Hex is not on the exam. So look into it if you're curious... but don't sweat it. Go study Threads some more, it'll be time better spent.
Bascially you should know that HEX numbers start with 0x, Octal numbers start with 0, Decimal numbers start with anything 1-9. And remember, the x in Ox can be capitalized too -- so OXDEAFCAB is the same as OxDeafCab is the same as Oxdeafcab --
TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
OK, thanks again Jess.
TM
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
In order to convert decimal to any base (hex, octal, or binary), you can continually divide the number by the base. Let me give you an example by converting the number 95 to all 3 bases.
First, we'll do binary:

Now, write down the remainders in reverse order that you got them: 1011111. There you have it - 1011111 is the binary version of 95. Let's try that with hex:

Again, we write down the remainders in reverse order and we have 0x5F, which is the hexadecimal representation of 95. Finally, let's do octal:

That gives us a value of 137, which is the octal representation of 95.
I hope that helps,
Corey


SCJP Tipline, etc.
TimD Moore
Greenhorn

Joined: Aug 19, 2003
Posts: 14
Thanks Corey, That does help.
TM
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hexadecimal
 
Similar Threads
regarding method in wrapper class...
valueof() method
conversions
Confusion creating String
maximum octal number for char is '\377'. why?