Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
ICP IP

ICP IP

Ratings:

4.0

(1)
|Views: 541|Likes:
Published by Đi Rong

More info:

Published by: Đi Rong on Jan 10, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/24/2010

pdf

text

original

 
CS 117Spring 2004Binary representation of numericaldata
April 14, 2004
Number representation
 
Computers store numbers, text, .... (any data) in
binary
¡ 
computers are just electrical circuits
¡ 
binary numbers (1, 0) are indications of 
voltage levels
 through these circuits (1 = “high”, 0 = “low”)
 
Text, audio, video: later
 
Numbers: need to represent
¡ 
integers
¡ 
reals (decimal values)
¡ 
negative and positive numbers
Integers
 
Base-10 integers: have a series of 
digits
whosevalue depends on the relative
 position
of thesedigits
¡ 
e.g. 543 = 5 100's, 4 10's, 3 1's
¡ 
= 5*10
2
+ 4*10
1
+ 3*10
0
¡ 
e.g. 13245 = 1*10
4
+ 3*10
3
+ 2*10
2
+ 4*10
1
+ 5*10
0
 
Positions
are powers of 10,
digits
are {0, 1, ..., 9}
Integers in base
n
 
Have same notion of 
 position
and
digits
¡ 
digits
: {0, 1, ...
n-1
}
¡ 
 positions:
powers of 
n
 
Example:
¡ 
1342 in base 6 = 1*6
3
+ 3*6
2
+ 4*6
1
+ 2*6
0
¡ 
10101 in base 2 (binary) = 1*2
4
+ 0*2
3
+ 1*2
2
+ 0*2
1
 + 1*2
0
 
Converting from base
n
to decimal
¢
Multiply digits by positions in the base
n
number,as on the previous slide
¢
Examples:
£ 
1342 in base 6 = 1*6
3
+ 3*6
2
+ 4*6
1
+ 2*6
0
= 350 inbase 10
£ 
10101 in base 2 (binary) = 1*2
4
+ 0*2
3
+ 1*2
2
+ 0*2
1
 + 1*2
0
= 21 in base 10
£ 
00100101 in binary = 1*2
5
+ 1*2
2
+ 1 = 37 in base 10
Converting from decimal to base
n
¢
Divide the decimal number repeatedly by the base
£ 
idea: find the largest power of 
n
that fits into thatdecimal number
£ 
at each stage, the
remainder 
becomes the leftmostdigit
£ 
carry the
quotient 
to the next stage
£ 
repeat until the quotient is zero
Converting from decimal to base
n
:examples
¢
543 to base 5:
£ 
543/5 = 108 rem 3
£ 
108/5 = 21 rem 3
£ 
21/5 = 4 rem 1
£ 
4/5 = 0 rem 4
£ 
= 4133
¢
982 to binary = ?
Example cont.
¢
982 from decimal to binary:
¤ 
982/2 = 491 rem 0
¤ 
491/2 = 245 rem 1
¤ 
245/2 = 122 rem 1
¤ 
122/2 = 61 rem 0
¤ 
61/2 = 30 rem 1
¤ 
30/2 = 15 rem 0
¤ 
15/2 = 7 rem 1
¤ 
7/2 = 3 rem 1
¤ 
3/2 = 1 rem 1
¤ 
1/2 = 0 rem 1
¥ 
= 1111010110
 
Representing negative numbers inbinary
¦
One approach:
signed-magnitude
§ 
for an 8-bit number, the first bit is the sign(0=positive, 1=negative), and the other 7 bits are thevalue
¨
can represent all numbers from -127 to 127
§ 
examples:
¨
1 = 00000001, -1 = 10000001
¨
65 = 01000001, -65 = 11000001
¨
0 = 00000000, -0 = 10000000 -->
problem!
Another way to represent negativenumbers:
two's complement 
¦
Allows us to represent negative numbers inbinary, without the “two zeros” problem
¦
All positive numbers start with a 0, as before
¦
Negative numbers:
§ 
Invert all the bits (change 0's to 1's and 1's to 0's)
§ 
Add 1 to this number
¦
With 8 bits, can represent all numbers from -128to 127
§ 
one extra than with signed-magnitude
More two's complement examples
¦
-7:
§ 
7 is 00000111
§ 
invert bits: 11111000
§ 
add 1: 11111001
¦
-127:
§ 
127 is 01111111
§ 
invert bits: 10000000
§ 
add 1: 10000001
¦
-1: 00000001 -> 11111110 -> 11111111
Scientific notation
¦
Expressing very large or very small numbers canbe tedious
§ 
e.g., 2147483647, 0.245689734921
¦
Scientific notation
allows us to express large orsmall numbers more compactly
§ 
show us the “order of magnitude” of the number,rather than all of the digits
¦
Format:
mantissa x 10
exponent 

Activity (4)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
elorejuela liked this
somolit liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->