Home > Archive > CCIE > December 2001 > decimal_to _hex conversion





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author decimal_to _hex conversion
darthfeces

2001-11-29, 10:18 pm

i seem to be having difficulty finding a system
or metheodology
to convert binary to hex in my head ???
i'd really like to not have to write out a
conversion table before i start the test

i know 0-9 a-f repeat repeat
but without writing down a table i'm finding it
difficult to convert off the top of my head

any idea's on a system for conversion
or neumonic shortcut ???

thanks
dmaftei

2001-11-30, 5:57 am

As a rule, it's very hard to do binary math in your head, because binary numbers get very long very quickly, and even short numbers like 150, which is 10010110, are hard to remember. But binary to hex and the other way around is very easy with a pen and a scrap of paper.

1. bin-to-hex: group the digits in groups of four, starting from the right; pad with zero to the left of the leftmost group; write the hex number for every group and you're done.

bin number: 110101110001011110101
group: 1 1010 1110 0010 1111 0101
pad: 0001 1010 1110 0010 1111 0101
replace with hex: 1AE2F5

2. hex-to-bin: replace every hex digit with its binary represantation (written with four bits), put those together, and maybe drop leading zeros, and you're done.

hex number: 2BA4
replace: 0010 1011 1010 0100
put together and drop leading 0s: 10101110100100
Mat P

2001-11-30, 9:09 am

I agree, that's the best way I've ever come across too.

It only takes a few seconds and has less margin for error. You can also use this method for Octal, just split the binary into blocks of three rather than four - never had reason to use it though!!
darthfeces

2001-11-30, 12:55 pm

i may be missing the pont in understanding
this but i mean,

decimal hex
10 = 0a
20 = 14
50 = 32
100 = 64
150 = 95
200 = c8
255 = ff
jcash2000

2001-11-30, 1:18 pm

[QUOTE]Originally posted by dmaftei
[B]As a rule, it's very hard to do binary math in your head, because binary numbers get very long very quickly, and even short numbers like 150, which is 10010110, are hard to remember. But binary to hex and the other way around is very easy with a pen and a scrap of paper.

1. bin-to-hex: group the digits in groups of four, starting from the right; pad with zero to the left of the leftmost group; write the hex number for every group and you're done.

bin number: 110101110001011110101
group: 1 1010 1110 0010 1111 0101
pad: 0001 1010 1110 0010 1111 0101
replace with hex: 1AE2F5


Could you explain the bin-to-hex step a little more? How did you get the group and pad? More to the point, what are they? And is that example a 21-bit number?
dmaftei

2001-11-30, 1:53 pm

quote:
Originally posted by darthfeces
i may be missing the pont in understanding
this but i mean,

decimal hex
10 = 0a
...


Well, although your subject line was decimal-to-hex, you asked about binary-to-hex in the post

I never do decimal-to-hex. I do decimal-to-binary, followed by binary-to-hex as above. But there are general algorithms to convert from a base to another. The algorithms differ based on the "direction" of the conversion: from small to big, or from big to small. Let me know if you want me to post the algorithms (they're a bit lengthy, and if nobody's interested I see no point in wasting the time.)
dmaftei

2001-11-30, 2:03 pm

quote:
Originally posted by jcash2000
Could you explain the bin-to-hex step a little more? How did you get the group and pad? More to the point, what are they? And is that example a 21-bit number?

You divide the binary number in groups of four because one hex digit is represented in binary by a four bit wide number:

0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
a 1010
b 1011
c 1100
d 1101
e 1110
f 1111

So, once the binary number is split in chunks of four (these "chunks of four" have a name, but I don't remember it), what's left is a mechanical replacement.

Zero-padding to the left in the leftmost group is not necessary, but it doesn't hurt either. (Note that you cannot drop the leading zeros when you do hex-to-bin, though...)

And yes, that's a 21 bit number (it happens to be 1762037), but it can be any number you want; I typed 1s and 0s randomly
darthfeces

2001-11-30, 3:37 pm

yes,
i realized that after the post that i meant .... decimal
either way thanks for the info and input
The Reamer

2001-11-30, 9:08 pm

What I have always done for decimal to hex conversions is to divide the number by 16. for example:

172/16=10 with a remainder of 12.
10 in hex is A, and 12 is C. So 172 would be AC.

Another example:

90/16=5 with a remainder of 10. So this would be 5A.

HTH,

Reamer
dmaftei

2001-11-30, 10:05 pm

quote:
Originally posted by The Reamer
What I have always done for decimal to hex conversions is to divide the number by 16.

That's about it for decimal to hex. How about hex to decimal?
MadChef

2001-12-01, 6:31 am

quote:
Originally posted by dmaftei

(these "chunks of four" have a name, but I don't remember it



I like the term "nibble" since it's half a byte. Heh.

BTW, why the need for converting hex to dec? I'm trying to think of a reason off the top of my head, but fail. The only conversion I ever find myself doing is hex <-> binary.
As another side note, you can check your math in IOS by doing something like configuring SRB. You can enter a number in hex and it will be represented in the config in decimal. So if you enter:

source-bridge ring-group 0x19

in your config you'll see

source-bridge ring-group 25

MC
darthfeces

2001-12-01, 6:34 am

sweet
thanks !
now it makes sense!

since hex 0-9 a-f you treat it like a "base16"
for the first digit and remainder is the second
digit ......... i need a liitle work on the
binary conversion but i'll get there
thanks all
Mat P

2001-12-01, 8:21 am

quote:
Originally posted by dmaftei
How about hex to decimal?


Hex to decimal is simply the opposite way. Convert from Hex, to binary, to decimal.

Separate your Hex into "nibbles", for example

2EA beomes:

0010 1110 1010
(2) (E) (A)

then convert this into decimal :
2+8+32+64+128+512=746

Hope that helps.
sidodgers

2001-12-02, 3:45 pm

People have probably stopped reading this thread, but i'll post this anyways....

The easiest way i've found to convert from decimal to hex (hex to decimal is easy,) is to (for single byte numbers, anyway) divide by 16.

eg, you have the decimal digit '172'. Dividing by 16 yields 10 with 12 remainder. coincidentally, 10 is the high order digit, and 12 is the low order digit, which gives us AC.

The reverse is a piece of cake, multiply 'A' by 16 and add 'C'.

HTH,

Sid
sidodgers

2001-12-02, 3:51 pm

quote:
Originally posted by sidodgers
People have probably stopped reading this thread, but i'll post this anyways....

The easiest way i've found to convert from decimal to hex (hex to decimal is easy,) is to (for single byte numbers, anyway) divide by 16.

eg, you have the decimal digit '172'. Dividing by 16 yields 10 with 12 remainder. coincidentally, 10 is the high order digit, and 12 is the low order digit, which gives us AC.

The reverse is a piece of cake, multiply 'A' by 16 and add 'C'.

HTH,

Sid



Oh, forgot to add, you can iterate this process for bigger numbers.

Let's say we have the number '65412' and want to represent it in hex.

The more perceptive would have picked up that for each digit, we're dividing by powers of 16. The trick is to know what the biggest decimal number you can represent in a hex string of a given length is. Common ones are below.

1 digit 15
2 digits 255
3 digits 4095
4 digits 65535
5 digits 1048575
6 digits 16777215

So, from this table, take the lowest number of digits where the maximum decimal number is bigger than the number you're trying to convert, then.

step 1. divide by 16^number of digits-1. quotient is hex digit for that position.
step 2. repeat, dividing remainder by 16^position-1.

so for 64512, we divide by 16^3 (4096). This gives us 0xF remainder 72.
divide 72 by 16^2 (256), which gives us 0 remainder 72.
divide 72 by 16, which gives us 4 remainder 8.
(anal retentive last step) divide 8 by 1, which gives us 8 remainder 0.

this process yields 0xF048, which is the hex representation of 64512.
dmaftei

2001-12-02, 4:34 pm

quote:
Originally posted by sidodgers
this process yields 0xF048, which is the hex representation of 64512.

Decimal 64512 is hex FC00 (and hex F048 is 61512).

As a matter of fact, you don't need to go through the trouble of remembering the powers of 16. You keep dividing (the initial number first, the quotients after that) until you get a quotient that's less then 16, and the quotient plus the remainders are the digits of the converted number in reverse order. For 64512:

64512 / 16 = 4032 remainder 0
4032 / 16 = 252 remainder 0
252 / 16 = 15 (0xF) remainder 12 (0xC)

Now you start with the last quotient, and take the remainders from bottom up: FC00.
dmaftei

2001-12-02, 4:51 pm

quote:
Originally posted by MadChef
I like the term "nibble" since it's half a byte. Heh.

Yep, "nibble" is the one. I'm wondering where it comes from...
sidodgers

2001-12-02, 8:06 pm

quote:
Originally posted by dmaftei

Decimal 64512 is hex FC00 (and hex F048 is 61512).

As a matter of fact, you don't need to go through the trouble of remembering the powers of 16. You keep dividing (the initial number first, the quotients after that) until you get a quotient that's less then 16, and the quotient plus the remainders are the digits of the converted number in reverse order. For 64512:

64512 / 16 = 4032 remainder 0
4032 / 16 = 252 remainder 0
252 / 16 = 15 (0xF) remainder 12 (0xC)

Now you start with the last quotient, and take the remainders from bottom up: FC00.



Oops... i knew something didn't seem 100% there... thanks for the clarification.
dmaftei

2001-12-02, 8:47 pm

Here's what I found at Merriam-Webster's about nibble:

quote:

nibble

Function: verb
Inflected Form(s): nib·bled; nib·bling /-b(&-)li[ng]/
Etymology: origin unknown
Date: circa 1512
transitive senses
1 a : to bite gently b : to eat or chew in small bits
2 : to take away bit by bit <waves nibbling the shore>
intransitive senses
1 : to take gentle, small, or cautious bites; also : SNACK
2 : to deal with something as if by nibbling

Function: noun
Date: 1658
1 : an act of nibbling
2 : a very small quantity or portion (as of food); also : SNACK
3 : a tentative expression of interest



To take cautious bites!! LOL
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2009 examnotes.net