Bianary to hex(sp?)

Anything and Everything about Uplink

Moderators: jelco, bert_the_turtle, Chris, Icepick, Rkiver

DeamonDreams
level0
Posts: 5
Joined: Sun Oct 26, 2003 9:36 am
Location: England
Contact:

Postby DeamonDreams » Tue Oct 28, 2003 11:14 am

I'm take a first dioploma in IT at college but am finding the conversion of bianary to hex difficult
i can do bi to decimal and visa versa no problem
but hex confuses me
i have to break the bianary up into blocks of 4 or something
please someone help me or directed me to a site that can please
i cant use convertors on the web either
i have to do it with paper and pencil
thanks in advance
-Me
Nil accidocisum sine lvcre
User avatar
Orillion
level3
level3
Posts: 382
Joined: Thu Oct 16, 2003 6:37 pm
Location: Israel, Tel-Aviv.
Contact:

Postby Orillion » Tue Oct 28, 2003 11:25 am

To convert a binary number to a decimal number you must first
understand what each digit in the binary number means. To explain this
let's look at the decimal number 247.

The '2' in 247 represents two hundred because it is a two in the
hundreds position (two times a hundred is two hundred). In similar
fashion, the '4' in 247 represents forty because it is a four in the
tens position (four times ten is forty). Finally, the '7' represents
seven because it is a seven in the units position (seven times one is
seven). In a decimal number, the actual value represented by a digit
in that number is determined by the numeral and the position of the
numeral within the number.

It works the same way with a binary number. The right-most position in
a binary number is units; moving to the left, the next position is
twos; the next is fours; the next is eights; then sixteens; then
thirty-twos ...  Notice that these numbers are all powers of two -
2^0, 2^1, 2^2, 2^3, 2^4, 2^5. (The units, tens, hundreds, thousands,
ten thousands of the decimal system are all powers of ten: 10^0, 10^1,
10^2, 10^3, 10^4).

So, to convert the binary number 1001 (don't read that as one thousand
one - read it as one zero zero one) to decimal, you determine the
actual value represented by each '1' and add them together.  The
right-most '1' has a decimal value of 1 (it is in the 2^0, or units,
position) and the left-most '1' has a decimal value of 8 (it is in the
2^3, or eights, position). So the binary number 1001 is equal to
decimal 9.  Here's another way to look at it:

    1 0 0 1
    ^ ^ ^ ^
    | | | |_________> 1 x 2^0 = 1 x 1 = 1
    | | |___________> 0 x 2^1 = 0 x 2 = 0
    | |_____________> 0 x 2^2 = 0 x 4 = 0
    |_______________> 1 x 2^3 = 1 x 8 = 8
                                       ---
                                        9

Both the decimal system and the binary system are positional number
systems. The hexadecimal system is another positional number system.  
The binary system has only two numerals - 0 and 1; the decimal system
has ten numerals: 0,1,2,3,4,5,6,7,8, and 9.  In the hexadecimal (or
hex) system there are sixteen numerals: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,
and F. Zero through nine have the same value as a decimal numeral, and
A is ten, B is eleven, C is twelve, D is thirteen, E is fourteen, and
F is fifteen. After a while you will get used to seeing "letters" used
as numerals!

The decimal number system is also referred to as "base ten" since each
position in a decimal number represents a power of ten - a number that
can be written as 10^n, where n is an integer. The binary number
system is also referred to as "base two" since each position in a
binary number represents a power of two - a number that can be written
as 2^n, where n is an integer. The hex number system is also referred
to as "base sixteen" since each position in a hexadecimal number
represents a power of sixteen - a number that can be written as 16^n,
where n is an integer.

The right-most position in a hexadecimal number is units; moving to
the left, the next position is sixteens; the next is two hundred
fifty-sixes; the next is four thousand ninety-sixes, and so on - all
powers of sixteen - 16^0, 16^1, 16^2, 16^3.

To convert a binary number to a hex equivalent, notice that four
binary digits together can have a value of from 0 to 15 (decimal)
exactly the range of one hex digit. So four binary digits will always
convert to one hex digit!

For example:

    10110111 = B7 (hex)

The right-most four digits of the binary number (0111) equal seven, so
the hex digit is '7'. The remaining left-most four digits of the
binary number (1011) equal eleven, so the hex digit is 'B'.  Here is
another way of looking at it:

       1 0 1 1 0 1 1 1     from right to left, make four-digit groups
       \      /\      /
        \    /  \    /
        eleven   seven     determine the decimal equivalent of each
           |       |       group
           V       V
           B       7        write the equivalent hexadecimal digit

What is the decimal equivalent of B7 hex?

    B 7
    ^ ^
    | |_________>  7 x 16^0 =  7 x  1 =   7
    |___________> 11 x 16^1 = 11 x 16 = 176
                                        ---
                                        183 decimal

Check that against the decimal equivalent of 10110111 binary:

    1 0 1 1 0 1 1 1
    ^ ^ ^ ^ ^ ^ ^ ^
    | | | | | | | |_________> 1 x 2^0 = 1 x   1 =   1
    | | | | | | |___________> 1 x 2^1 = 1 x   2 =   2
    | | | | | |_____________> 1 x 2^2 = 1 x   4 =   4
    | | | | |_______________> 0 x 2^3 = 0 x   8 =   0
    | | | |_________________> 1 x 2^4 = 1 x  16 =  16
    | | |___________________> 1 x 2^5 = 1 x  32 =  32
    | |_____________________> 0 x 2^6 = 0 x  64 =   0
    |_______________________> 1 x 2^7 = 1 x 128 = 128
                                                  ---
                                                  183 decimal

Hope this helps.  Good luck in your class!
Made you look!
DeamonDreams
level0
Posts: 5
Joined: Sun Oct 26, 2003 9:36 am
Location: England
Contact:

Postby DeamonDreams » Tue Oct 28, 2003 2:09 pm

thankyou so much
i actually understand now
i was getting confused of what the base numbers were and what to times the base numbers by to get the correct numbers
anyway i get it now
thanks again
Nil accidocisum sine lvcre
Darksun
level5
level5
Posts: 6461
Joined: Sat Dec 07, 2002 7:08 pm
Location: 127.0.0.1

Postby Darksun » Tue Oct 28, 2003 4:22 pm

Actually, Orillion, that is BCD - binary coded decimal, its different to proper binary
bgreene2001
level5
level5
Posts: 1310
Joined: Sat Dec 22, 2001 3:46 pm
Location: Melbourne, Australia

Postby bgreene2001 » Tue Oct 28, 2003 5:05 pm

No, actually groups of 4 bits actually map to a single hex digit.  If you were doing the same thing, but not going over 9 (ie, no hex digits, just decimal digits), then it would be binary coded decimal.  If you can't see how it works, then just try it :)

It's how I generally do decimal -> hex on paper, via binary.  Much quicker than the method of subtracting multiples of 16^n, and heaps better than repeated division by 16 in your head :)

[damn CCNA not letting us have even a calculator :P]
I swear Officer, I didn't know she was 4!
My Profile, my mates site, Bloody Mongrel.  Great stuff.
Click here to help me get some free magnets :)  Pleeeease?
Stewsburntmonkey
level5
level5
Posts: 11553
Joined: Wed Jul 10, 2002 7:44 pm
Location: Nashville, TN
Contact:

Postby Stewsburntmonkey » Tue Oct 28, 2003 7:57 pm

It still amuses me that Comp. Sci. classes make people do this by hand, I mean there is a reason we devised the computer.  It is good to have a general understanding of the the issues involved, but it much more useful to understand how things are represented in binary than how to translate binary into hex or whatever.  :)
Adam Black
level4
level4
Posts: 594
Joined: Mon Mar 18, 2002 5:37 pm
Location: London, England

Postby Adam Black » Tue Oct 28, 2003 8:23 pm

Or you could just use Icepick's Converter.


The Converter
Let's kick this bitch into overdrive.
River
level1
level1
Posts: 15
Joined: Sun Oct 26, 2003 9:52 pm
Location: USA
Contact:

Postby River » Wed Oct 29, 2003 3:01 am

Yeah, I'm in a Compsci class myself, learning Java. (hey, it's a start, lol) We've had to learn how to do binary, hex, and base ten conversions.. it's a bit strange to do on paper, but not too hard if you're decent at math. But I agree, why do it on paper if you're in front of a computer? Maybe in case one day we have to devise the actual meaning of a binary number to hex in order to save some main business server and we have no laptops at hand, lol...
l3inaryl3urnout
level1
level1
Posts: 16
Joined: Tue Sep 02, 2003 2:33 am
Contact:

Postby l3inaryl3urnout » Wed Oct 29, 2003 4:31 am

HEY GUYS BETTER YET... USE THE TOOLS MICROSOFT GIVES YOU!!

incase you guys didnt know if you view your microsoft calculator under scientific and all you have to do is type in the bin or hex or dec or oct or whatever your using and click the button that corrosponds with what you want like hex or dec or oct or bin... its the easy way to do it
bgreene2001
level5
level5
Posts: 1310
Joined: Sat Dec 22, 2001 3:46 pm
Location: Melbourne, Australia

Postby bgreene2001 » Wed Oct 29, 2003 10:12 am

I've actuall found that in a lot of situations, it's quicker to do it by hand (after enough practive of course).  I find it takes me longer to type in the number, change to the other base, and copy it down, than it does simpl to do it on paper.  Especially for binar to decimal, and between binary and hex.
I swear Officer, I didn't know she was 4!
My Profile, my mates site, Bloody Mongrel.  Great stuff.
Click here to help me get some free magnets :)  Pleeeease?

Return to “General”

Who is online

Users browsing this forum: No registered users and 18 guests