Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


c for new ex s to make the mistake of saying,
, is mistake
e we ountin ng
untin wi th r.
hen you count like a com
mputer h lien h ou and the
last would be 15 (0xF if it was speaking hex instead of dec). Try to keep this in
ind because it will bite you later.


Experienced microcontroller programmers memorize the binary equivalent of hex
or instance, given 0xA9, what would
e LEDs (or the voltage states of an 8-bit register) look like? If you memorize the


r, ask the same question in decimal,
1 like on a luck, on doing that in your head.
ok at Ap ee e byte s d binary.
lly, all bite ar

ar
name o t for c t
a character SCII character set ppendix 4 – ASCII Table). Originally,
e were II ch s use to transmit and
eive data te Figur wrote C,
nding ne ho Teletype
ine. C y (the hompson),
letypes were light years ahead of switches
presenting each bit of data. Teletypes send and receive characters so a lot of C,
specially the standard library, is character oriented. The number of bits in a char
achine dependent, but in all machines I’ve encountered including the AVR, a
char is an 8-bit byte which can have 256 bit states. The computer uses this byte of
data as representing a signed value from –128 to + 127.


The ASCII code was extended to include characters for 128 to 255 primarily to do
weird European characters, math symbols, and character graphics on early PCs.


It is very
ell there are 16 hex integers, so 0xF


ommon users of h number
‘W the last one, is 16.’ We make th
becaus omputer use you’ll
co


think of c g beginni
is

with 1, but for most c
see
W


g beginning th 0. 0
puter your first digit (left thum

e first integer and 15 is the 16th intege
b?) is 0 not 1. If a
co ad those a ands to c nt on, the first thumb would be 0


m


digits and find hex numbers very useful. F
th
table, you come up with 0xA = 1010 and 0x9 = 1001, so the LEDs (voltage states)
will look like: 10101001. As pointed out earlie
what will 69 look the LEDs nd good
Lo pendix 5 to s all th tates in decimal, hexadecimal, an
Fina jokes equating byte to e prohibited.


ch
The f this data type i
in the A


s shor haracter, and is typically used to represen
(A
ther 127 ASC aracter d by Teletype machines
rec. You will no that in e 1, you see Dennis Ritchie, who
sta xt to Ken T mpson, who wrote UNIX, working on a
mach lunky as the were Teletype, not Ritchie and T
Te entering data by individual
re
e
is m

Free download pdf