Week11-Bits - Bit arrays King 20.1 20.2 Bit strings Signal mask and file descriptor sets are implemented using bit array or bit strings You should

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Bit arrays King: 20.1, 20.2 !!
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Bit strings • Signal mask and file descriptor sets are implemented using bit array or bit strings. • You should always use the supplied functions macros to manipulate these structures. • It is useful to know how they are implemented. • Each bit represents an element of the set – 1 == in the set – 0 == not in the set
Background image of page 2
Bitwise operators • shift (note that bits fall off the ends) << left shift >> right shift i = 6; /* 0000 0000 0000 0110 */ j = i << 2 /* 0000 0000 0001 1000 */ k = i >> 2 /* 0000 0000 0000 0001 */ – set bit at index 10 (start indexing at 0) j = 10; i = 1 << j /* 0000 0100 0000 0000 */
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Bitwise Complement, And, Or Xor • ~ complement • & and • ^ xor • | or i = 17; /* 0001 0001 */ j = 3; /* 0000 0011 */ k = ~j; /* 1111 1100 */ n = i | j /* 0001 0011 */ o = i ^ j /* 0001 0010 */
Background image of page 4
Idioms • Setting a bit string to all 1s: – i = ~0; or i = -1; • Set all but the last 2 bits to 1: – i = ~0x3; • Setting bit j – x = 1 << j; – or – x = 0; – x |= 1 << j;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/02/2011.

Page1 / 11

Week11-Bits - Bit arrays King 20.1 20.2 Bit strings Signal mask and file descriptor sets are implemented using bit array or bit strings You should

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online