posted 17 years ago
Conversions from binary to octal and binary to hexadecimal and vice versa are pretty simple.
For example, if you have a binary string and you want to convert it to
1. octal, then left pad the String with 0 until the number of digits is a multiple of 3. Then divide the String into groups of 3 and convert each to its octal equivalent (000 = 0, 001 = 1, 010=2, 011=3, 100=4, 101=5, 110=6, 111=7).
2. hexadecimal, then left pad the String with 0 until the number of digits is a multiple of 4. Then divide the String into groups of 4 and convert each to its hexadecimal equivalent (0000 = 0, 0001 = 1, 0010 = 2, 0011 = 3, 0100 = 4, 0101 = 5, 0110 = 6, 0111 = 7, 1000 = 8, 1001 = 9, 1010 = A, 1011 = B, 1100 = C, 1101 = D, 1110 = E, 1111 = F).
For the reverse, its even easier.
To convert from
1. octal to binary, replace each digit with its three digit binary equivent.
2. hexadecimal to binary, replace each digit with its four digit binary equivalent.