lecture28-apr8 - Lecture 28 Announcements Assignment 6 Out...

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

View Full Document Right Arrow Icon
Lecture 28 Announcements • Assignment 6 – Out today; designs due Friday at recitation • No lecture on Friday • Topics of the day – More Low level programming • Bit field operations • Bit structure operations •Examp le s Bit-field Operators • Dealing with several consecutive bits (called a bit-field) within a value is slightly more complicated. • Bit-fields and values should have the type: unsigned int, or signed int. – Using int by itself is ambiguous; some compilers treat the high-order bit as a sign bit, while others don’t. – Use unsigned or signed variables only • How it works is different for individual variables and structs Bit-field Operators Modifying a bit-field within a value • 1) Use a mask containing 0 bits in each position to be modified to clear those bits, then 2) store the pattern needed. i = i & 0xff8f | 0x0050; /* stores bits 101 in bits 4-6 */ • If the new value of the bit-field is stored in a variable, the variable must be shifted before the | operator is applied: j = 5; i = i & 0xff8f | j |, so this statement is equivalent to i = (i & 0xff8f) | (j << 4); Retrieving a bit-field • Retrieving a bit-field at the right end of a variable is done by clearing all the others to the left j = i & 0x0007; /* retrieves bits 0-2 */ • If the bit-field is not at the right end, then extract the field using the & operator, then shift the result to the right: j = (i & 0x0070) >> 4; /* retrieves value in bits 4-6 */
Background image of page 1

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

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

This note was uploaded on 01/24/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas.

Page1 / 4

lecture28-apr8 - Lecture 28 Announcements Assignment 6 Out...

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

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