Page 1 of 1

Equations to convert hex, bin and oct from decimal

Posted: Thu Jul 10, 2008 8:13 am
by inflater
Hi,
does anybody know if any "equation" or some sort does exist when you want to convert e.g. some hexadecimal number to decimal without using calculator?

Re: Equations to convert hex, bin and oct from decimal

Posted: Thu Jul 10, 2008 5:08 pm
by iammisc
to convert to any base, simply find the representation of the base to convert from in the base to convert to. For example, this means that if you want to convert from base-16 to base-8, this number would be 20 and base-8 to base-10 would 8. Then simply, multiply each digit of the number from right-to-left by the former number raised to consecutive powers starting at 0.

For example, converting 0x7EA6 from base-16 to base-8 would yield the following:

(7 * (20 ^ 3)) + (16 * (20 ^ 2)) + (12 * (20 ^ 1)) + (6 * (20 ^ 0)) ==

(7 * 10000) + (16 * 400) + (12 * 20) + 6 = 70000 + 7000 + 240 + 6 = 77246

similarly, converting 0x7EA6 from base-16 to base-10 would be:

(7 * (16 ^ 3)) + (14 * (16 ^ 2)) + (10 * (16 ^ 1)) + (6 * (16 ^ 0)) ==
(7 * 4096) + (14 * 256) + (10 * 16) + 6 = 28672 + 3584 + 160 + 6 = 32256 + 166 = 32422

Re: Equations to convert hex, bin and oct from decimal

Posted: Fri Jul 11, 2008 12:55 am
by DeletedAccount
binary to hex and binary to oct are very easy
For hex - form groups of 4 n convert to hex
for oct - form groups of 3 n convert to oct
eg
1000 0111 binary = 87 hex
eg
For
111 100 binary = 74 octal
Generalizing the above formula :
hexadecimal to decimal = Summmation from i = 0 to n ai *( 16 ^ i )
ie ai is the i th hex digit in decimal
i varies from zero to n where n is the total number of digits -1