Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


0x08 = 00001000 = 0x08
-----

r maybe myByte = 0x55:

myByte x55
0x08 08


OR 5D


This all shows bit of myByte is affected by the OR operation,
since it is the only bit equal to 1 in 0x08.


e can set bit 3 with:

myByte = 00000000 = 0x00

------------------------





OR = 00001000 = 0x08


Suppose myByte = 0xFF:


myByte = 11111111 = 0xFF
0x08 = 00001000 = 0x00


OR = 11111111 = 0xFF


O


= 01010101 = 0
= 00001000 = 0x

= 01011101 = 0x

that only the 3rd

Now let’s do the same thing with the & operator:


unsigned char myByte = 0;


W


myByte = myByte & 0x08;


To see what’s happening Let’s look at these in binary:


0x08 = 00001000 = 0x08


AND = 00000000


Suppose myByte = 0xFF:


myByte = 11111111 = 0xFF
0x08 = 00001000 = 0x08

Free download pdf