Download presentation
Presentation is loading. Please wait.
Published byAubrie McLaughlin Modified over 6 years ago
1
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
Sign-magnitude BCD Real Convert from decimal to binary Binary scientific notation
2
Scheme III: Sign-magnitude
Leftmost bit works like a +/- sign. Remaining bits behave like unsigned. Example: what is ? Leftmost bit “1” means number is negative Remaining bits are 1001 = 9, so entire number is –9 What would –20 look like in 8 bits? +20 looks like or To make it negative, change first bit to 1.
3
Scheme IV: BCD “Binary Coded Decimal” Ex. 278 = 0010 0111 1000
Only good for positives. Each decimal digit corresponds to 4 bits. Easy conversion for binary decimal Ex = If we have 8 bit BCD, what is the range? Waste Purpose – easy conversion to/from base 10
4
Having enough bits Question – Are 6 bits sufficient to represent the number 50? Answer – Depends on the rep’n scheme. Let’s look at each one. Avoiding overflow
5
Integer vs. Real Integer arithmetic on computer is quick and exact, but limited range Real arithmetic needs wide range, reasonable degree of precision Preferred for numerical computation 14 significant digits is usually enough!
6
Binary examples Look at this sequence: 111 = 7 1110 = 14 11100 = 28
= 56 = 112 Let’s go the other way 111. = 7 11.1 = 3.5 or 7/2 1.11 = 1.75 or 7/4 .111 = 7/8 .0111 = 7/16
7
Another example 10100 = 20 1010 = 10 101 = 5 10.1 = 2.5 or 5/2
.101 = 5/8 Each digit corresponds to (+/–) power of 2. For example, the binary equals what in decimal?
8
Convert to binary Separate number (e.g. 5.7) into integer and fractional parts. Integer part? Binary store. Fractional part: Keep multiplying fractional part by 2 until it becomes zero, or until you have a repeating pattern.
9
Example Convert 9.625 to binary. “9” becomes 1001.
Fractional part is 0.625: .625 * 2 = 1.25 .25 * 2 = 0.5 .5 * 2 = 1.0 Fractional part reached 0. So answer is
10
Example Let’s convert 4.6875 to binary The “4” becomes 100.
Fractional part is : .6875 * 2 = 1.375 * 2 = 0.75 * 2 = 1.5 * 2 = 1.0 Fractional part reached 0. So answer is
11
Repeating pattern Let’s try converting 0.7 to binary. .7 * 2 = 1.4
.4 * 2 = 0.8 .8 * 2 = 1.6 .6 * 2 = 1.2 .2 * 2 = 0.4 And we’ve seen “.4” already ____ Answer is … or Note the bar.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.