23.10.2013 Views

M68HC05 Family — Understanding Small Microcontrollers

M68HC05 Family — Understanding Small Microcontrollers

M68HC05 Family — Understanding Small Microcontrollers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Freescale Semiconductor, Inc...<br />

Computer Numbers and Codes<br />

Binary Coded Decimal<br />

Freescale Semiconductor, Inc.<br />

When mentally translating octal values to binary byte values, the octal<br />

value is represented by three octal digits. Each octal digit represents<br />

three binary bits so there is one extra bit (3 digits × 3 bits = 9 bits). Since<br />

Western-speaking people typically work from left to right, it is easy to<br />

forget to throw away the leftmost extra bit from the leftmost octal digit<br />

and end up with an extra (ninth) bit. When translating from hexadecimal<br />

to binary, it is easier because each hexadecimal digit translates into<br />

exactly four binary bits. Two hexadecimal digits exactly match the eight<br />

binary bits in a byte.<br />

Binary coded decimal (BCD) is a hybrid notation used to express<br />

decimal values in binary form. BCD uses four binary bits to represent<br />

each decimal digit. Since four binary digits can express 16 different<br />

physical quantities, there will be six bit-value combinations that are<br />

considered invalid (specifically, the hexadecimal values A through F).<br />

BCD values are shown with a $ sign because they are actually<br />

hexadecimal numbers that represent decimal quantities.<br />

When the computer does a BCD add operation, it performs a binary<br />

addition and then adjusts the result back to BCD form. As a simple<br />

example, consider the following BCD addition.<br />

910 + 110 = 1010<br />

The computer adds<br />

0000 10012 + 0000 00012 = 0000 10102<br />

But 10102 is equivalent to A16, which is not a valid BCD value. When the<br />

computer finishes the calculation, a check is performed to see if the<br />

result is still a valid BCD value. If there was any carry from one BCD digit<br />

to another or if there was any invalid code, a sequence of steps would<br />

be performed to correct the result to proper BCD form. The 0000 10102<br />

is corrected to 0001 00002 (BCD 10) in this example.<br />

<strong>M68HC05</strong> <strong>Family</strong> <strong>—</strong> <strong>Understanding</strong> <strong>Small</strong> <strong>Microcontrollers</strong> <strong>—</strong> Rev. 2.0<br />

34 Computer Numbers and Codes<br />

For More Information On This Product,<br />

Go to: www.freescale.com<br />

MOTOROLA

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!