File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# Conversion

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi guys,
I have one very basic doubt. Could somebody be kind enough to clear this. I still have problem to convert hexadecimal numbers to binary.
ex:How to convert 0xff into binary number. Please teach me the trick. Giving the exam in couple of days.
Any help would be highly appreciated.
Thanks a bunch.
sathish
Ranch Hand

Joined: Apr 25, 2000
Posts: 33
hi uma
A short solution.
first take the positional values for the one you are converting
for e.g: a Hexadecimal can have 4096, 256, 16, 1 and then identify the exact decimal equivalent of the number or character from the Decimal- Hexadecimal representation chart..( you know from 0 to 9 the numbers are the same in Hexadecimal and 10-A, 11-B, 12-C, 13-D, 14-E, 15-F)assign & multiply with the Postional values. Finally add all those and you will get the decimal equivalent.
eg: 0x0012 equivalent to 18. ( 1 * 16 + 2 * 1)
i found this to be quick and hope this is of use to you
Sathish
sathish
Ranch Hand

Joined: Apr 25, 2000
Posts: 33
uma
i thought you were asking to convert to decimal, Ok it's again simple
Much simple
Write the Hexadecimal digit or alphabet as it's 4-digit binary equivalent.
e.g 0x0012
0000 0000 0001 0010 and you get 18.
sathish
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

Sathish:
Now out of curiosity ...and necessity ...
What abt 0xff which "uma" asked.
Could you (or anyone else, I am sooooo generous )
help with this ...
Thanks.
- satya
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks satish. But one more question are there going to be any questions like what's the result of 0x63^0xbd(i found this in apllied reasoning mock exam). Because it took way too much time for me to figure out answer to this q. First i had to convert those numbers to decimal format and then to binary format and then perform the calculation and then again convert the result into hexadecimal format. Could you please tell me some simple way to find out the answer for these kind of q's. Appoxmately how many q's of this type will be given in the test.
Kindly help me with some detailed info.
Thanks.

sreelakshmi sarma
Ranch Hand

Joined: Mar 02, 2000
Posts: 130
Satya,
f is equal to 15 in hexadeciaml.So, 0xff will be 16^0*15+16^1*15.That would be 255 in decimal format.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

Thanks sree.....
I shold have known the case insensitivity ....
(now I remember 0x?? 0X?? )
phttt...too much caffine in my brain I guess
- satya
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Satya,
You have to know this by heart if you want to apply the easy method in order to convert a hex literal to an integer value.
One technique I use generally is I can write upto 9 easily. After that I just add the extra values. In other words, If i have to write 'D' for example, I know 1001 is for 9, in order to get D I have to add(1+1+1+1) (A..B..C..D) which means I have to add 9+4 = 13 = 1101.
<pre>

1 - 0000
2 - 0001
3 - 0010
4 - 0011
5 - 0100
6 - 0101
7 - 0110
8 - 0111
9 - 1000
A - 1010
B - 1011
C - 1100
D - 1101
E - 1110
F - 1111

</pre>
So if you know this chart at your finger tips, then it is very easy to convert a hex to a binary.
As Sathish said,
<pre>

0xFF = 0x 1111 1111 = 255 as int value

I am sure you know how to convert binary to a number. All those bit0*(2^0) + bit1*(2^1).....
regds
maha anna
Harry Chawla
Ranch Hand

Joined: Jun 03, 2000
Posts: 97
Hi Uma
Picking up from where Satish and Anna have stopped, it's obvoius that for ur case oxff, conversion from hex to binary will be
1111 1111.
I believe u need not mug up the chart, as th binary conversion is pretty straigt forward.
One more thing to add out here, if it's a conversion from octal to binary, use a set of three binary digits(2*2*2), instead of four binary digits(2*2*2*2) used for Hex numbers.
All the best for your exams. I'll give it a shot in May end.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

As always ... Thanks Maha.
Infact I was thinking of leaving all this stuff.
There was a related discussion on "shifting" by
Brian Nice. I wanted to ask abt conversion in that
discussion, but took it easy !
I mean, howmuch ??
Now, I understand why some people (I talked to) said
"oh, no its too much work for me...".
hmmm...the exam is real real work ....
Regds.
- satya
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks a lot guys.

I agree. Here's the link: http://aspose.com/file-tools

subject: Conversion