DMP - Chapter 15
Bit Fiddling
Signed integers
Two's complement (invert + 1): -1 == 11111111, -128 == 1000000
One's complement (invert only): -1 == 11111110, -0 == 11111111
Octal (e.g. 0377 == 1111111)
Hexadecimal
Bitwise operators: ~, &, |, ^
Masks (&);
Bit on (| MASK), off (| -MASK)
Toggling bits (^ MASK)
Structure contents in a file
Checking the value of a bit (flag & MASK) == MASK
Bitwise shift operators (<<, >>)
Bit fields
struct
{
unsigned bit1: 1;
unsigned bits: 4;
unsigned bit3: 2;
} flag;
Assignment #14 (Due 21 Jan. 1997):
p.534: #1, 3, 4, 5.
Write MIDI Note (On, Off) to text function. It should take 3 hex bytes (use a struct) and output Type (On or Off), Channel number, Note number, and velocity.
Go to Ich's Home Page
Go to the Peabody Home Page
For comments or questions
email
to:
ich@peabody.jhu.edu