Skip to content

Base R1 to Base R2 Conversion

We can do conversion from any base R1 to any base R2 by doing two operations instead of one:

  1. Convert from base R1 to base 10.
  2. Convert from base 10 to base R2.

R1 to R2 Conversion Algorithm

graph LR A["Base 2"] --> X["Base 10"] --> B["Base 2"] C["Base 8"] --> X["Base 10"] --> D["Base 8"] E["Base 16"] --> X["Base 10"] --> F["Base 16"] G["Base R1"] --> X["Base 10"] --> H["Base R2"]

Of course, if can be quite tedious to keep on converting to and from base 10. We will show you some shortcut that is applicable only in some scenario.

Base 2 ↔ Base 8

Quick Conversion Algorithm

  1. Partition into groups of 3 from the dot.
  2. Add leading and/or trailing zeroes to complete the group.
  3. Convert each group into octal.
Why is step 3 never produce number outside the range of octal? (click to see answer)

We group each bit into groups of 3. The largest value is (111)2 which is equal to 7. Clearly, 7 is within the range of octal.

  1. Convert each octal digit into exactly 3 bits.
  2. We may need to leading and/or trailing zeroes.

Quick Conversion

Convert (10111011001.101110)2 to octal.

Step
1 10 111 011 001 . 101 110
2 010 111 011 001 . 101 110
3 2 7 3 1 . 5 6

So, (10111011001.101110)2 = (2731.56)8.

Convert (2731.56)8 to binary.

Step
0 2 7 3 1 . 5 6
1 010 111 011 001 . 101 110
2 10 111 011 001 . 101 11

So, (2731.56)8 = (10111011001.10111)2.

Quick Quiz
  1. Convert (10110010101.0100101)2 to octal.
  2. Convert (21.02)8 to binary.
  1. (2625.224)8

    Steps
    1
    2
    3
    4
        10 110 010 101 . 010 010 1
    => 010 110 010 101 . 010 010 100
    => 2   6   2   5   . 2   2   1
    => 2625.221
    
  2. (10001.00001)2

    Steps
    1
    2
    3
    4
       2   1   . 0   2
    => 010 001 . 000 010
    =>  10 001 . 000 01
    => 10001.00001
    

Base 2 ↔ Base 16

Quick Conversion Algorithm

  1. Partition into groups of 4 from the dot.
  2. Add leading and/or trailing zeroes to complete the group.
  3. Convert each group into hexadecimal.
Why is step 3 never produce number outside the range of hexadecimal? (click to see answer)

We group each bit into groups of 4. The largest value is (1111)2 which is equal to 15 or F. Clearly, this is within the range of hexadecimal.

  1. Convert each hexadecimal digit into exactly 4 bits.
  2. We may need to leading and/or trailing zeroes.

Quick Conversion

Convert (10111011001.101110)2 to hexadecimal.

Step
1 101 1101 1001 . 1011 10
2 0101 1101 1001 . 1011 1000
3 5 D 9 . B 8

So, (10111011001.101110)2 = (5D9.B8)16.

Convert (5D9.B8)16 to binary.

Step
0 5 D 9 . B 8
1 0101 1101 1001 . 1011 1000
2 101 1101 1001 . 1011 1

So, (5D9.B8)16 = (10111011001.10111)2.

Quick Quiz
  1. Convert (110100100101001.01010001011)2 to hexadecimal.
  2. Convert (BABA.9090)16 to binary.
  1. (6929.516)16

    Steps
    1
    2
    3
    4
        110 1001 0010 1001 . 0101 0001 011 
    => 0110 1001 0010 1001 . 0101 0001 0110
    => 6    9    2    9    . 5    1    6
    => 6929.516
    
  2. (1011101010111010.100100001001)2

    Steps
    1
    2
    3
    4
       B    A    B    A    . 9    0    9    0
    => 1011 1010 1011 1010 . 1001 0000 1001 0000
    => 1011 1010 1011 1010 . 1001 0000 1001
    => 1011101010111010.100100001001
    

Other Cases?

Let's take a look at the shortcuts above. We have a few magic numbers. If we look at it in more details, we may be able to generalise the pattern that leads to the given magic number.

Consider the justification for which the grouping works. Using groups of 3, we can convert base 2 into base 8. Note that 23 = 8. We see that this pattern also holds for base 2 into base 16 where 24 = 16.

It is then reasonable to assume that given base R, we can convert it to base Rn easily using the shortcut by grouping. The group size should be n.

Without going into much details, we can give an example of converting base 3 to base 9 by virtue of 32 = 9.

Base 3 to Base 9

Convert (12202.012)3 to base 9.

Step
1 1 22 02 . 01 2
2 01 22 02 . 01 20
3 1 8 2 . 1 6

So, (12202.012)3 = (182.16)9

Quick Quiz

Quickly convert (CA.FE)16 to base 4.

(3022.3332)4

Steps
1
2
3
   C  A  . F  E
=> 30 22 . 33 32
=> 3022.3332

You may combine the two methods. If you find that the bases are powers of 2, then convert it to base 2 and then convert from base 2. In both cases, you use the grouping shortcut method.

Steps
1
2
3
4
5
   C     A     . F     E
=> 1100  1010  . 1111  1110   // Group by 4
=> 11 00 10 10 . 11 11 11 10  // Re-group by 2
=> 3  0  2  2  . 3  3  3  2
=> 3022.3332

Exercises

Exercise

Quickly convert (7345)8 to base 16.

(EE5)16

Steps
1
2
3
4
5
   7345
=> 7    3    4    5
=> 111  011  100  101 // base 8 to base 2
=> 1110 1110 0101     // base 2 to base 16
=> E    E    5