L02 - CMU 18-447 S'07 L2-1 2008 J. C. Hoe 18-447 Lecture 2:...

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

View Full Document Right Arrow Icon
CMU 18-447 S’07 L2-1 © 2008 J. C. Hoe 18-447 Lecture 2: Computer Arithmetic: Adders James C. Hoe Dept of ECE, CMU January 16, 2008 Announcements: Verilog Refresher? Review P&H Appendix B Read P&H Chap 3 Handouts: CMU 18-447 S’07 L2-2 © 2008 J. C. Hoe Binary Number Representation ± Let b n-1 b n-2 …b 2 b 1 b 0 represent an n-bit unsigned integer ­ its value is ­ a finite representation between 0 and 2 n -1 ­ e.g., 1011 two = 8 ten + 2 ten + 1 ten = 11 ten (more commonly rewritten as b’1011=11) ± Often written in Hex for easier human consumption ­ to convert, starting from the LSB, map 4 binary digits at a time into a corresponding hex digit; and vice versa ­ e.g., 1010_1011 two =AB hex For converting between binary and decimal, memorize decimal values of 2 0 ~ 2 10 , and remember 2 10 is about 1000. = 1 0 2 n i i i b value of the i’th digit weight of the i’th digit
Background image of page 1

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

View Full DocumentRight Arrow Icon
CMU 18-447 S’07 L2-3 © 2008 J. C. Hoe 2’s-Complement Number Representation ± Let b n-1 b n-2 …b 2 b 1 b 0 represent an n-bit signed integer ­ its value is ­ a finite representation between -2 n-1 and 2 n-1 -1 ­ e.g., assume 4-bit 2’s-complement b’ 1 011 = -8 + 2 + 1 = -5 b’ 1 111 = -8 + 4 + 2 + 1 = -1 ± To negate a 2’s-complement number ­ add 1 to the bit-wise complement ­ assume 4-bit 2’s-complement (- b’ 1 011) = b’ 0 100 + 1 = b’ 0 101 = 5 (- b’ 0 101) = b’ 1 010 + 1 = b’ 1 011 = -5 (- b’ 1 111) = b’ 0 000 + 1 = b’ 0 001 = 1 (- b’ 0 000) = b’ 1 111 + 1 = b’ 0 000 = 0 = + 2 0 1 1 2 2 n i i i n n b b CMU 18-447 S’07 L2-4 © 2008 J. C. Hoe Intuition: a 4-bit example 4-bit 16 values (whether signed or unsigned) b’0000=0 (as 2’s), 0 (as unsigned) b’1000=-8, 8 b’0001=1, 1 b’0010=2, 2 b’0011=3, 3 b’0100=4, 4 b’0101=5, 5 b’0110=6, 6 b’0111=7, 7 b’1111=-1, 15 b’1110=-2, 14 b’1101=-3, 13 b’1100=-4, 12 b’1011=-5, 11 b’1010=-6, 10 b’1001=-7, 9 ± how to add two numbers ± what it means to “overflow” the number representation ± how to negate a number Yes, 0 is a positive number in CS
Background image of page 2
CMU 18-447 S’07 L2-5 © 2008 J. C. Hoe Smaller to Larger Binary Representation ± Unsigned numbers ­ pad the left with as many 0s as you need (aka 0-extension) e.g. 4’b1111 8’b0000_1111 ± 2’s-complement numbers ­ positive: pad the left with as many 0s as you need ­ negative: pad the left with as many 1s as you need e.g. 4b’ 1 111 8’b 1111 _ 1 111 4b’ 1 110 8’b 1111 _ 1 110 ­ or generically, pad the left with the same value as the original sign-bit as many times as necessary (aka signed- extension) What about converting from larger to smaller representation?
Background image of page 3

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

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

This note was uploaded on 04/07/2008 for the course ECE 18447 taught by Professor Hoe during the Spring '08 term at Carnegie Mellon.

Page1 / 13

L02 - CMU 18-447 S'07 L2-1 2008 J. C. Hoe 18-447 Lecture 2:...

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

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