 About me Home Resumé CV Pictures Course Work CSE300-FA98 Teaching Portfolio CSE240-SP99 CSE207-FA03 Misc eHarmony Documents Tools # Number Systems - Conversions

## BaseN to Decimal

All number systems going from BaseN to Decimal can be done using the following approach. Take every character in the current base and multiply it by the radix (N) to the power of the position. Next convert each character to its decimal equivalent. Add up all of these terms to get the decimal value of the number.

Example: Binary to Decimal

10010011Base2
= `1`*27 + `0`*26 + `0`*25 + `1`*24 + `0`*23 + `0`*22 + `1`*21 + `1`*20
= 147Base10

Example: Hexadecimal to Decimal

= `1`*162 + `A`*161 + `D`*160
= 1*162 + 10*161 + 13*160
= 429Base10

## Decimal to BaseN

All number systems going from Decimal to BaseN can be done using either of the following approaches.

### Formal Approach

Take the decimal and divide by the new radix (N). The remainder of this division is the least significant digit in the new radix. Treat the quotient of the division as the new number and repeat the process. This remainder will be the next least significant digit.

Example: Decimal to Binary

1073/2 = 536 R `1` (LSB)
536/2 = 268 R `0`
268/2 = 134 R `0`
134/2 = 67 R `0`
67/2 = 33 R `1`
33/2 = 16 R `1`
16/2 = 8 R `0`
8/2 = 4 R `0`
4/2 = 2 R `0`
2/2 = 1 R `0`
1/2 = 0 R `1` (MSB)
Therefore 1073Base10 = 100 0011 0001Base2

### Alternate Approach

Precompute successive powers of the radix until you have a number greater than the number you are trying to convert. Subtract the largest power from your starting number without producing a negative result. Record a `1` next to this power. Repeat the process for the result of your subtraction until you get to zero. This is the inverse of the process used to go from BaseN to Decimal. Digits in the new radix are produced from MSB to LSB in this method. Remember this is the opposite of the order of bits produced in the approach above.

Example: Decimal to Binary

1073 - 1024 = 49 (result so far = `1`)
skip 512 too big (result so far = `10`)
skip 256 too big (result so far = `100`)
skip 128 too big (result so far = `1000`)
skip 64 too big (result so far = `10000`)
49 - 32 = 17 (result so far = `100001`)
17 - 16 = 1 (result so far = `1000011`)
skip 8 too big (result so far = `10000110`)
skip 4 too big (result so far = `100001100`)
skip 2 too big (result so far = `1000011000`)
1 - 1 = 0 (result so far = `10000110001`)
Therefore 1073Base10 = 100 0011 0001Base2 Last Modified: - Barry E. Mapen