Bitwise-AND

You can also bitwise-AND two bytes together to create a third. In this case, a bit on the third byte is 1 only if the corresponding bits in the first two bytes are both 1.

Figure 38.4  Two bytes bitwise-ANDed together

Two bytes bitwise-ANDed together

This is done with the & operator. Add the following lines to main.c:

#​i​n​c​l​u​d​e​ ​<​s​t​d​i​o​.​h​>​ i​n​t​ ​m​a​i​n​ ​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ​a​r​g​v​[​]​)​ {​ ​ ​ ​ ​u​n​s​i​g​n​e​d​ ​c​h​a​r​ ​a​ ​=​ ​0​x​3​c​;​ ​ ​ ​ ​u​n​s​i​g​n​e​d​ ​c​h​a​r​ ​b​ ​=​ ​0​x​a​9​;​ ​ ​ ​ ​u​n​s​i​g​n​e​d​ ​c​h​a​r​ ​c​ ​=​ ​a​ ​|​ ​b​;​ ​ ​ ​ ​p​r​i​n​t​f​(​"​H​e​x​:​ ​%​x​ ​|​ ​%​x​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.