CS 24000 Lecture Notes - Lecture 6: Switch Statement

20 views4 pages

Document Summary

Bitwise operations: not : the ~ negates bits unsigned x = 0x05; // 0000000 0000000 0000000 00000101 unsigned y = ~x; // ~00000101 = 11111111 11111111 11111111 11111010 printf( x=0x%x 0x%x\n , x,y); // x=0x5 y=0xfffffffa. Using bitwise operations: test if bit i is set: int i = 4; unsigned x = 23; // x = 00010111. // test if bit i is set in x. // create mask with bit i set. unsigned mask = (1 << i); // mask == 00010000. // test if bit i is set unsigned y = (x & mask); // y = 00010111 & 00010000 =00010000 int bit = (y >> i); // bit = 00000001. Using bitwise operations set bit i int i = 3; unsigned x = 23; // x = 00010111. // create mask with bit i set. unsigned mask = (1 << i); // mask == 0001000.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers