lecture28-apr7 - 4/7/10 Lecture 28 Announcements Exam 2...

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

View Full Document Right Arrow Icon
4/7/10 1 Lecture 28 Announcements • Exam 2 status – Average and median ~= 74 – Hand back on Friday • Assignment 6 out Tomorrow, due in 2 weeks • Read Chapter 20 (low level programming) • Topics of the day: think in binary today – Low level programming (for systems) – Bit twiddling • Bit values are 1 or 0 – Machine dependent operations Low Level Programming • Usually machine dependent by nature – Storage unit differences and alignment issues – R to L, or L to R allocation of bits to units • Bit (byte) level manipulations are necessary for: – Operating systems, compilers, etc. – Encryption programs – Graphics – Embedded systems – Intelligent devices – others where fast execution or space utilization is critical • Portability is compromized unless the machine dependent computations are encapsulated – E.g. only use unsigned or signed variables • Lack of programmer documentation is an absolute killer in this area • You must know your binary and hexidecimal numbers Bit Level Operations • Performed on integer values in C (including char) • For example, on a sixteen bit value ( short int ) in which the bits are numbered from right to left (as in Windows – big endian ) 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0’s 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 0 Shift bits to the left 0’s 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 0 (or sign bits, if a signed value) Shift bits to the right Bitwise Shifting • The bitwise shift operators are: << left shift >> right shift • The expression i << j means the value of i is shifted left j positions, with zeros-filled in on the right. • The expression i >> j means i shifted right j positions. – If i is of an unsigned type or if the value of i is not negative, then zero bits are added on the left as needed. – If i is negative, the result is machine dependent. Usually the
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.

Page1 / 3

lecture28-apr7 - 4/7/10 Lecture 28 Announcements Exam 2...

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