+ All Categories
Home > Documents > Data Representation

Data Representation

Date post: 30-Dec-2015
Category:
Upload: columbia-adriel
View: 27 times
Download: 0 times
Share this document with a friend
Description:
Data Representation. CS 1428. 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. Bits, Bytes, and so on. A bit is one 0 or 1 - PowerPoint PPT Presentation
17
CS 1428
Transcript

CS 1428

Binary Representation of InformationDetecting Voltage Levels

Why not 10 levels? Would be unreliable Not enough difference between states

On/OffFully Charged - Fully DischargedMagnetized - Demagnetized

2

Bits, Bytes, and so onA 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

The Binary Numbering SystemA 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

Binary Representation of Numeric and Textual InformationBinary numbering system

Base-2Built from ones and zerosEach position is a power of 2

1101 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20

Decimal numbering systemBase-10Each position is a power of 10

3052 = 3 x 103 + 0 x 102 + 5 x 101 + 2 x 100

5

Binary NumbersBase 2 - digits 0 and 1

___ ___ ___ ___ ___ ___25 24 23 22 21 20

6

7

Calculating in binaryFirst practice counting to 2010 in binary

Practice adding: 10112 + 1012

Try subtracting: 10112 - 1012

8

Representing Signed NumbersWhat 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 methodReserve 1 bit (usually the high-order bit) that

represents the signRest of the bits make up the magnitude

Sign-and-MagnitudeEasy to understand but not efficientTwo representations for zeroLot of extra overhead to do binary arithmeticRecall 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?

2’s complementThe high-order bit represents the sign but the

magnitude is computed differentlyHas a single representation for zeroHas an extra negative numberNo extra overhead for binary arithmetic Almost all modern computers use this

representationExample

Converting Decimal to 2’s ComplementGet the binary representation for the

absolute value of the numberFlip all the bitsAdd 1 to the complement Example

-3 00011 // 5-bit binary for absolute value of -311100 // all bits flipped 11101 // 1 added to the complement

Converting 2’s Complement to DecimalIf the high-order bit is 0 then convert the

number in the usual wayElse

Subtract 1Flip all bitsConvert to decimalAffix a minus sign

Converting 2’s Complement to DecimalExample

11010 // 2’s complement binary11001 // 1 subtracted00110 // bits flipped-6 // affixed the negative sign

2’s Complement ArithmeticBinary addition, discard the final carryExample

00111110--------0001

Be careful of overflowFor a 5 bit 2’s complement representation

16 is too large! -17 is too small!

More on 2s Complementhttp://en.wikipedia.org/wiki/Two's_compleme

nthttp://www.hal-pc.org/~clyndes/computer-ari

thmetic/twoscomplement.html

SummaryThings you should be able to do

Convert binary to decimalConvert decimal to binaryConvert 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


Recommended