Search code examples
binarydecimaldata-conversionoctal

How to convert Binary to Decimal and Octal?


I have a BINARY number which i want to convert it into the DECIMAL and OCTAL.

(0100 1111 1011 0010)2

I know how to convert it into the decimal. But the question making me confuse. Because middle of every 4 digits there is a space "0101 1111" can u help me how to understand this question.

Thanks


Solution

  • First of all, make sure that number you are converting into Decimal and Octal is actually 'Binary' and not 'Binary Coded Decimal (BCD)'. Usually when the number is grouped into 4 binary digits, it represents a BCD instead of just binary.

    So, once you make sure its actually binary and not BCD, the conversion to both decimal and octal are simple steps.

    For binary to octal, you group the binary number into sets of 3 digits, starting form the Least Significant Bit(LSB or right-most) to the Most Significant Bit(MSB or left-most). Add leading zeros if a group of 3 digits can not be formed at the MSB.

    Now convert each group of digits from binary to octal:

    (000) -> 0 (001) -> 1 . . (111) -> 7

    Finally put the numbers together, and there you have your binary converted to octal.

    Eg:- binary - 00101101 split into groups of 2: -> 000 101 101 -> 0 5 5 - > 55

    Difference between'Binary Coded Decimal' and 'Binary':

    For the decimal number 1248 the binary would simply be 10011100000 However, the BCD would be -> 0001 0010 0100 1000