Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 1428. Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off.

Similar presentations


Presentation on theme: "CS 1428. Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off."— Presentation transcript:

1 CS 1428

2 Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off Fully Charged - Fully Discharged Magnetized - Demagnetized 2

3 Bits, Bytes, and so on A bit is one 0 or 1 Short for “binary digit” A byte is a collection of 8 bits They named it “byte” instead of “bite” so you couldn’t easily mess up the spelling and confuse it with “bit”. 3

4 The Binary Numbering System A computer’s internal storage techniques are different from the way people represent information in daily lives We see and type numbers and letters. The computer sees ones and zeros for everything All information inside a digital computer is stored as a collection of binary data 4

5 Binary Representation of Numeric and Textual Information Binary numbering system Base-2 Built from ones and zeros Each position is a power of 2 1101 = 1 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0 Decimal numbering system Base-10 Each position is a power of 10 3052 = 3 x 10 3 + 0 x 10 2 + 5 x 10 1 + 2 x 10 0 5

6 Binary Numbers Base 2 - digits 0 and 1 __________________ 2 5 2 4 2 3 2 2 2 1 2 0 6

7 7

8 Calculating in binary First practice counting to 20 10 in binary Practice adding: 1011 2 + 101 2 Try subtracting: 1011 2 - 101 2 8

9 Representing Signed Numbers What about negative numbers? We can divide the bit patterns into two halves but we need to be careful What to do for zero? Need to consider binary arithmetic as well One approach is to use the sign and magnitude method Reserve 1 bit (usually the high-order bit) that represents the sign Rest of the bits make up the magnitude

10 Sign-and-Magnitude Easy to understand but not efficient Two representations for zero Lot of extra overhead to do binary arithmetic Recall the ALU from Lecture 1 ALU does binary arithmetic (mainly addition) We would need to redesign the ALU to do arithmetic with sign-and-magnitude representation What’s the alternative?

11 2’s complement The high-order bit represents the sign but the magnitude is computed differently Has a single representation for zero Has an extra negative number No extra overhead for binary arithmetic Almost all modern computers use this representation Example

12 Converting Decimal to 2’s Complement Get the binary representation for the absolute value of the number Flip all the bits Add 1 to the complement Example -3 00011 // 5-bit binary for absolute value of -3 11100 // all bits flipped 11101 // 1 added to the complement

13 Converting 2’s Complement to Decimal If the high-order bit is 0 then convert the number in the usual way Else Subtract 1 Flip all bits Convert to decimal Affix a minus sign

14 Converting 2’s Complement to Decimal Example 11010 // 2’s complement binary 11001 // 1 subtracted 00110 // bits flipped -6 // affixed the negative sign

15 2’s Complement Arithmetic Binary addition, discard the final carry Example 0011 1110 -------- 0001 Be careful of overflow For a 5 bit 2’s complement representation 16 is too large! -17 is too small!

16 More on 2s Complement http://en.wikipedia.org/wiki/Two's_complement http://www.hal-pc.org/~clyndes/computer- arithmetic/twoscomplement.html http://www.hal-pc.org/~clyndes/computer- arithmetic/twoscomplement.html

17 Summary Things you should be able to do Convert binary to decimal Convert decimal to binary Convert 2’s complement binary to decimal Convert decimal to 2’s complement binary Towards the end of the semester perhaps write a program that does this for you


Download ppt "CS 1428. Binary Representation of Information Detecting Voltage Levels Why not 10 levels? Would be unreliable Not enough difference between states On/Off."

Similar presentations


Ads by Google