How to Convert a BCD Code to a Different Number Base

Binary coded decimal (BCD) notation finds use in computer programming because of its ability to conserve on memory storage capacity. Writing a piece of decimal data in binary code can occur in two different ways: one is by converting the number as a whole into binary, and the alternate method is to convert the decimal number into binary digit by digit. Using BCD code there is no upper limit on the allowed size of a number, but when converting the decimal number as a whole into binary, the largest number usable is determined by the capabilities of the processor and data bus of the computer. Common number bases used in computer programming are 2, 8, 10 and 16. Each base describes the numbers that are used in expressing values and governs the way numbers are manipulated.

Instructions

    • 1

      Write the BCD code for a number you need to convert to a base. The BCD code is a series of 4-bit binary numbers that correspond to each digit in the base number system. For example, using the base 10 or decimal system number 138, the BCD code has 12 bits. Each 4 bits represents a single digit in the decimal number. The first digit is 1 so the BCD code is 0001. The next two digits are composed in the same manner, namely 3 is 0011 and 8 is 1000. The BCD code representation of decimal 138 is 000100111000 or simplified as 100111000.

    • 2

      Select the number base into which you want the BCD coded number converted. The most common bases used in computer programming are binary (base 2), octal (base 8) and hexadecimal (base 16).

    • 3

      Decode the BCD coded number into decimal format. There is no direct way to convert BCD code to a different base. To write the number in a base of your choosing you must convert from decimal to that base. For example, decode the following BCD coded decimal number (Base 10), 1001011100101001. Convert the BCD code into the decimal number by grouping the bits into sets of 4 bits and then convert each group of four bits into the decimal digit. The four groups are 1001, 0111, 0010 and 1001. These convert to 9729.

    • 4

      Divide the decimal number by the value of the base you are converting into. The remainder of the division fills in the least significant position of the result. Divide the integer portion of the result by the value of the base again. The integer portion carries forward and the remainder of the division fills into the next least significant position in the result. This continues until the integer portion is too small to divide by the value of the base. For example, convert 312 decimal into base 4. The following series of calculations will yield the answer in base 4. 312 / 4 = 78 remainder 0. Least significant digit of answer 0. 78 / 4 = 19 remainder 0.5. The next digit in the answer is 4 x 0.5 = 2. 19 / 4 = 4 remainder 0.75. The next digit is 0.75 x 4 = 3. 4 / 4 = 1 remainder 0. The next digit is 0. The next digit in the answer is 1 / 4 = remainder 0.25. The last digit is 0.25 x 4 = 1. Put these together to get the answer, 10320 base 4.

Learnify Hub © www.0685.com All Rights Reserved