Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


seconds after eleven in the morning.
nd that conversion is easy compared to the numbers you get if you set your

years seventy-eight days six hours
urteen minutes and seven seconds later. So we are going to need to do some
t to something we can read.

binary numbers, say a count of the crystal beats, to decimal numbers, like you’d


mber with a range of 0 to 16. That’s one
f the r
us to s


ount

indicate that the time is ten minutes and 41
A
watch at thirty-three seconds after three twenty in the afternoon on May 11th of
2005 and you are reading the number two
fo
computing to convert the coun


We’ll briefly explore one way to convert time from byte sized data to ASCII text
strings that we can understand.


BCD - Binary Coded Decimal


Binay Coded Decimal is a coding trick that eases the storage and conversion of


want to display on a watch LCD. We can divide an 8-bit byte into two 4-bit
nibbles each of which can represent a nu
o easons for the use of hexadecimal notation discussed earlier. And it allows
tore as single decimal integers, 0 to 9, in a nibble and two in a byte, one
integer in each nibble.


If a the decimal number in a byte is less than 99, we can convert it to a BCD byte
using the following algorithm:


Set the initial byte (in C we use char) to some two digit value.


char initialbyte = 54;


Declare a variable for the upper nibble value.


char high = 0;

C the tens in initialbyte.


while (initialbyte >= 10)
{
high++;
initialbyte -= 10;
}

Free download pdf