MedVision ad

decimal to hexadecimal conversion (1 Viewer)

aerialsprite

New Member
Joined
Oct 30, 2003
Messages
19
I remember doing a trial where for question 24 some of the commands we had to write were in hexadecimal.

Does anyone know how to covert from decimal to binary and then to hexadecimal and octal? I know I did it in the preliminary course - I've just forgotten....^^;;
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
It's very easy, i do it a long way but it's fast for me and i'm comfortable with it



Dec - Bin


Say the number 129, i first write down my power's of 2's


128 64 32 16 8 4 2 1 (You start from the right and continuously double the number)


ok so for 129 we know that 'a' 128 is in it, so therfore in the place value we put a 1, there's no 64 because 128 + 64 wouldn't equal to 129, so we put a zero there, and moving down all the place values none of them added onto 128 gives the output of until we meet the last place value which is 1, 1+ 128 = 129, so we bit a 1 in it. so the result will be

Code:
128     64    32     16      8    4   2   1

1        0       0         0       0   0   0   1

now that we know the binary equivalent we can then convert to hexadecimal

we know that for a fact hexadecimal works in 4-Bits, so we break that binary equivalent into 4-bits

[1000] [0001]

We now convert these two binary sets back to normal digits

so 1000 = 8

0001 = 1

therefore the hexadecimal equivalent is 81


Some notes on Hexadecimal conversion, when you break the binary equivalent into 4 bits if your left with say for example

01 [0001] [0100]

you can add the zero's up for 01 to make it a 4 bit, i.e. 0001

And in Hexadecimal

say if the if you converted your 4 bit equivalent binary number back into a normal number

if it's 10 it will equal A this is the letters representation for Hex

0 = 0
1 = 1
2 = 2
3 = 3
4 = 4
5 = 5
6 = 6
7 =7
8 = 8
9 = 9
10 = A
11 = B
12 = C
13 = D
14 = E
15 = F

It stops there that's the whole number system for Hexdecimal, as it's base 16 meaning there's only 16 numbers in it's number system

so let's say we had a binary equivalent set as


[0011] [1010]

then 0011 = 3

1010 = 10, but this is Hex so we know 10 = A

Thefore the hexdecimal equivalent is 3A

As for reversing the process


if they gave you a Hexdecimal number, lets take 3A again as the example

we write the binary equiavlent for each digit, in 4 Bit's

so 3 = 0011
A = 1010

then we just join them back up

00111010

and work out the decimal equivalent

Hope this helped you out


As for Octal, it's not in the syllabus but if it's not hard to learn


In octal the number system is based on 8 numbers, so it's 0 to 7

You do it the exact method i taught you above, convert decimal to Binary, but this time we don't split them up into 4 bits, we split them up into 3 bits, and then convert each 3 bit to a decimal equivalent
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Winston's method is great, and realistically questions are highly likely to require both the binary and hex conversion.

However to convert from decimal to any other base you just divide continually by the base. The remainders will be your answer in reverse order.

For example to convert 100 to hex:

100/16 = 6 r 4
6/16 = 0 r 6

So the answer in hex is 64

Try it with a big number, say convert 1000 to hex:

1000/16= 62 r 8
62/16= 3 r 14
3/16=0 r 3

As 14 in hex is represented as E the answer is 3E8

It works in binary too, try converting 100 base 10 to base 2:

100/2=50 r 0
50/2=25 r 0
25/2=12 r 1
12/2=6 r 0
6/2=3 r 0
3/2=1 r 1
1/2= 0 r 1

So the answer is 1100100

HTH
Sam
 

freaking_out

Saddam's new life
Joined
Sep 5, 2002
Messages
6,786
Location
In an underground bunker
Gender
Male
HSC
2003
yeah, also sometimes u mite b asked to convert (for example) binary to hexidecimal, if u've forgotten how to, then just convert binary to decimal and then to hexidecimal- well thats what i do, since i can't remember all those techniques sometimes. :mad1:
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by Lundy
don't worry, I've been completely lost ever since I started sdd
i must admit it is quite confusing if u dont enjoy the subject, and havent experienced many of some of the computing aspects for example many ppl in my class dont get parameters (arguments) i understood becoz i use it alot in programming and i know wat it is.
 

ANTONE

Member
Joined
Oct 19, 2003
Messages
34
Location
Nowhere
wot you guys rekon is the most effective and best way to absorb as much information as posable, so close to the exam?

I need a merical... :p
 

saves.the.day

Member
Joined
Oct 29, 2003
Messages
233
Location
Castle Hill
Gender
Undisclosed
HSC
2003
Originally posted by SamD
However to convert from decimal to any other base you just divide continually by the base. The remainders will be your answer in reverse order.

For example to convert 100 to hex:

100/16 = 6 r 4
6/16 = 0 r 6

So the answer in hex is 64

Try it with a big number, say convert 1000 to hex:

1000/16= 62 r 8
62/16= 3 r 14
3/16=0 r 3

As 14 in hex is represented as E the answer is 3E8
This method is excellent. I have seriously never seen this method before..
Stupid question time though: would this be valid to use in the HSC? because by dividing by base you aren't really showing that you have knowledge that hex is taken by dividing the binary bit into two nibbles of 4 bits? Or am I just paranoid?
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by saves.the.day
This method is excellent. I have seriously never seen this method before..
Stupid question time though: would this be valid to use in the HSC? because by dividing by base you aren't really showing that you have knowledge that hex is taken by dividing the binary bit into two nibbles of 4 bits? Or am I just paranoid?

i hate dividing, i mean i can do the basic binary converting division method but hell dividing by 16 without a calc will kill
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
If the question just asks you to convert from decimal to hex or from decimal to binary then use this method. If it asks to convert from binary to hex or hex to binary, then examining each nibble is the way to go.

Sam
 

saves.the.day

Member
Joined
Oct 29, 2003
Messages
233
Location
Castle Hill
Gender
Undisclosed
HSC
2003
Thankyou Sam (talk about a quick reply). I want to thankyou again for this method, It's amazing how quick/easy it is.
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
I'm supposed to be proofing my IPT prelim book. But it gets boring reading stuff that you wrote yourself, looking for dumb commas, sem-colons and stuff!!! So your questions are a diversion...
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top