CS 24000 Study Guide - Midterm Guide: Switch Statement

37 views2 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+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents