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 numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "hexadecimal numbers" Watch "hexadecimal numbers" New topic
Author

hexadecimal numbers

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

I am having some confusion about how to convert hexadecimal numbers to decimal. Could someone please go through a simple explanation for me? My main confusion is what do the letters mean? (like 0xffa) (I do not mean toHexString() either. I mean using a brain and pencil) Thanks!!!
Viji Bharat
Ranch Hand

Joined: Sep 18, 2000
Posts: 101
Remember this table for
Hex Decimal equivalent
0..9 0..9
A 10
B 11
C 12
D 13
E 14
F 15
To convert a hex to decimal, do this
Start from the right most hex value going towards left. Multiply the rightmost hex value by 16 to the power of 0. Multiply second right hex value by 16 to the power of 1. etc. Now, add all these values to get the decimal equivalent.
Lets take an Eg. Lets convert Hexadecimal AF to its decimal equivalent
A F
| |_ X 16 <sup>0</sup> (16 power 0)
|
|_ X 16 <sup>1</sup> (16 power 1)
From the table above F -> 15, A -> 10
So, the decimal equivalent is 15 X 16 <sup>0</sup> + 10 X 16 <sup>1</sup>
= 15 + 160
= 175
HTH
[This message has been edited by Viji Bharat (edited October 19, 2000).]
Rob Levo
Ranch Hand

Joined: Oct 01, 2000
Posts: 167
Hex A = 10 Decimal
Hex B = 11 Decimal
Hex C = 12 Decimal
Hex D = 13 Decimal
Hex E = 14 Decimal
Hex F = 15 Decimal
To convert hex(base 16) to decimal(base 10)
right most digit(or letter) = digit * 16^0 (1)
next digit = digit * 16^1
next digit = digit * 16^2
etc
Hope that was clear.
Originally posted by Barry Andrews:
I am having some confusion about how to convert hexadecimal numbers to decimal. Could someone please go through a simple explanation for me? My main confusion is what do the letters mean? (like 0xffa) (I do not mean toHexString() either. I mean using a brain and pencil) Thanks!!!

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Thanks folks! This makes sense to me now!!!
 
 
subject: hexadecimal numbers
 
Threads others viewed
Java Object Reference Variable Question
char
Representation
Literal for binary number
Range related 2
Two Laptop Bag