A binary number uses only two types of digits, 0 and 1. These digits are called binary digits, or abbreviated to bits. Although binary numbers are suitable for computers, they are not suitable for general use because they run out of bits quickly. This is revealed by a look at the first eight integers in their binary and decimal forms:
Note that one bit can represent up to the decimal number 1. Two bits extend this figure to 3 (11),while 3 bits can represent up to 7 (111). The maximum number that can be represented with 8 bits is 2 -1 = 255, which needs only 3 digits in decimal. In general, the maximum number that can be represented with n bits is 2″ – 1.
How to convert from Binary to Decimal
How does one compute the decimal value of a binary number? Simply multiply each digit by its assigned weight and then sum the weighted values. To see how this is actually done, split the binary number 10101 into its constituent bits and align them with their weights and weighted values:
Note that the weights increase proportionately as the digits are traversed from right to left. Adding the products in the third row (16 + 0 + 4+0 + 1) yields 21, which is the decimal value of 10101. Nothing could be simpler than that!
How to Convert from Decimal to Binary
Conversion from decimal to binary calls for employing a totally different technique Divide the decimal number repeatedly by 2 and collect all the remainders. The binary equivalent is the revered sequence of these reminders. The following examples employ this method for converting the decimal numbers 6, 19 and 32 to binary. The first line shows the division to be performed Subsequent lines display the progressive quotient and remainder.
Let’s examine the first example. Division is performed three times:
(1). 6 is divided by 2. This produces the quotient 3 and remainder 0.
(2). 3 is divided by 2. Both quotient and remainder are 1.
(3). 1 is divided by 2. The quotient is 0 and the remainder is 1.
The remainders are thus generated in this sequence: 011. Reverse this sequence to 110 and you have the binary equivalent of 6. Note from all three examples that division is terminated when the quotient is 0 and the remainder is 1.
Binary Coded Decimal (BCD)
Many devices like pocket calculators have LED displays where each digit is represented by a set of seven segments. Such devices store numbers in binary code decimal (BCD), where each decimal digit is stored in binary form. For instance, the number (254)10, which is 11111110 in pure binary (8 bits), is represented as 0010 0101 0100 in BCD (12 bits). Here are a few more examples:
Any decimal digit can be represented with 4 bits, so packed BCD uses 4 bits (half a byte or one nibble) for each digit. The third column shows the packed BCD representation. Unpacked BCD takes up 8 bits (one byte or two nibbles) for each digit The last example suggests that a three-digit decimal number like 127, which is represented by 7 digits in binary, takes up 12 bits in packed BCD and 24 bits in unpacked BCD.
Note that BCD (packed or unpacked) takes up more space because cach of the decimal digits is codified separately. This wastage can be justified in situations where fractional numbers are involved. A decimal number having a fractional component can be accurately converted only to BCD and not to binary.