Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)

Similar presentations


Presentation on theme: "Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)"— Presentation transcript:

1 Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)

2 Why Binary? Maximal distinction among values  minimal corruption from noise Imagine taking the same physical attribute of a circuit, e.g. a voltage lying between 0 and 5 volts, to represent a number The overall range can be divided into any number of regions CSC 370 (Blum)

3 Don’t sweat the small stuff
For decimal numbers, fluctuations must be less than 0.25 volts For binary numbers, fluctuations must be less than 1.25 volts 5 volts 0 volts Decimal Binary CSC 370 (Blum)

4 Range actually split in three
High Forbidden range Low CSC 370 (Blum)

5 It doesn’t matter …. Two of the standard voltages coming from a computer’s power supply are ideally supposed to be 5.00 volts and volts Typically they are 5.14 volts or volts or some such value. So what, who cares. CSC 370 (Blum)

6 How to represent big integers
Use positional weighting, same as with decimal numbers 205 = 2  100 = 127 + 126 + 025 + 0 23 + 122 + 021 + 1 = = 205 CSC 370 (Blum)

7 Converting 205 to Binary 205/2 = 102 with a remainder of 1, place the 1 in the least significant digit position Repeat 102/2 = 51, remainder 0 1 1 CSC 370 (Blum)

8 Iterate 51/2 = 25, remainder 1 25/2 = 12, remainder 1
1 1 CSC 370 (Blum)

9 Iterate 6/2 = 3, remainder 0 3/2 = 1, remainder 1 1/2 = 0, remainder 1
1 1 1 CSC 370 (Blum)

10 Recap 205 1 127 + 126 + 025 + 024 + 123 + 122 + 021 + 120
CSC 370 (Blum)

11 Adding Binary Numbers Same as decimal; if the sum of digits in a given position exceeds the base (10 for decimal, 2 for binary) then there is a carry into the next higher position 1 3 9 + 5 7 4 CSC 370 (Blum)

12 Adding Binary Numbers 1 + carries CSC 370 (Blum)

13 Uh oh, overflow What if you use a byte (8 bits) to represent an integer A byte may not be enough to represent the sum of two such numbers. 1 CSC 370 (Blum)

14 Biggest unsigned integers
4 bit: 1111  15 = 8 bit:  255 = 28 – 1 16 bit:  65535= 216 – 1 32 bit:  = 232 – 1 Etc. CSC 370 (Blum)

15 Bigger Numbers You can represent larger numbers by using more words
You just have to keep track of the overflows to know how the lower numbers (less significant words) are affecting the larger numbers (more significant words) CSC 370 (Blum)

16 Negative numbers Negative x is the number that when added to x gives zero Ignoring overflow the two eight-bit numbers above sum to zero 1 CSC 370 (Blum)

17 Two’s Complement Step 1: exchange 1’s and 0’s
Step 2: add 1 (to the lowest bit only) 1 1 1 CSC 370 (Blum)

18 Riddle 1 Is it 214? Or is it – 42? Or is it Ö? Or is it …?
It’s a matter of interpretation How was it declared? 1 CSC 370 (Blum)

19 3-bit signed and unsigned
7 1 6 5 4 3 2 3 1 2 -1 -2 -3 -4 Think of driving a brand new car in reverse. What would happen to the odometer? CSC 370 (Blum)

20 Biggest signed integers
4 bit: 0111  7 = 8 bit:  127 = 27 – 1 16 bit:  32767= 215 – 1 32 bit:  = 231 – 1 Etc. CSC 370 (Blum)

21 Hexadecimal Numbers Even moderately sized decimal numbers end up as long strings in binary Hexadecimal numbers (base 16) are often used because the strings are shorter and the conversion to binary is easier There are 16 digits: 0-9 and A-F CSC 370 (Blum)

22 Decimal  Binary  Hex 0  0000  0 1  0001  1 2  0010  2
3  0011  3 4  0100  4 5  0101  5 6  0110  6 7  0111  7 8  1000  8 9  1001  9 10  1010  A 11  1011  B 12  1100  C 13  1101  D 14  1110  E 15  1111  F CSC 370 (Blum)

23 Binary to Hex Break a binary string into groups of four bits (nibbles)
Convert each nibble separately 1 E C 9 CSC 370 (Blum)

24 Numbers from Logic All of the numerical operations we have talked about are really just combinations of logical operations E.g. the adding operation is just a particular combination of logic operations Possibilities for adding two bits 0+0=0 (with no carry) 0+1=1 (with no carry) 1+0=1 (with no carry) 1+1=0 (with a carry) CSC 370 (Blum)

25 Addition Truth Table INPUT OUTPUT A B Sum A XOR B Carry A AND B 1
1 CSC 370 (Blum)

26 Multiplication: Shift and add
1 + shift shift CSC 370 (Blum)

27 Fractions Similar to what we’re used to with decimal numbers 3.14159 =
3 · · · · · · 10-5 = 1 · · · · · · · · 2-6 (  ) CSC 370 (Blum)

28 Converting decimal to binary II
98.61 Integer part 98 / 2 = 49 remainder 0 49 / 2 = 24 remainder 1 24 / 2 = 12 remainder 0 12 / 2 = 6 remainder 0 6 / 2 = 3 remainder 0 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder 1 CSC 370 (Blum)

29 Converting decimal to binary III
98.61 Fractional part 0.61  2 = 1.22 0.22  2 = 0.44 0.44  2 = 0.88 0.88  2 = 1.76 0.76  2 = 1.52 0.52  2 = 1.04 CSC 370 (Blum)

30 Another Example (Whole number part)
Integer part 123 / 2 = 61 remainder 1 61 / 2 = 30 remainder 1 30 / 2 = 15 remainder 0 15 / 2 = 7 remainder 1 7 / 2 = 3 remainder 1 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder 1 CSC 370 (Blum)

31 Checking: Go to Programs/Accessories/Calculator
CSC 370 (Blum)

32 Put the calculator in Scientific view
CSC 370 (Blum)

33 Enter number, put into binary mode
CSC 370 (Blum)

34 Another Example (fractional part)
Fractional part 0.456  2 = 0.912 0.912  2 = 1.824 0.824  2 = 1.648 0.648  2 = 1.296 0.296  2 = 0.592 0.592  2 = 1.184 0.184  2 = 0.368 CSC 370 (Blum)

35 Checking fractional part: Enter digits found in binary mode
Note that the leading zero does not display. CSC 370 (Blum)

36 Convert to decimal mode, then
CSC 370 (Blum)

37 Divide by 2 raised to the number of digits (in this case 7, including leading zero)
CSC 370 (Blum)

38 In most cases it will not be exact
CSC 370 (Blum)

39 Other way around Multiply fraction by 2 raised to the desired number of digits in the fractional part. For example .456  27 = Throw away the fractional part and represent the whole number 58 111010 But note that we specified 7 digits and the result above uses only 6. Therefore we need to put in the leading 0 CSC 370 (Blum)

40 Fixed point If one has a set number of bits reserved for representing the whole number part and another set number of bits reserved for representing the fractional part of a number, then one is said to be using fixed point representation. The point dividing whole number from fraction has an unchanging place in the number. CSC 370 (Blum)

41 Limits of the fixed point approach
Suppose you use 4 bits for the whole number part and 4 bits for the fractional part (ignoring sign for now). The largest number would be = The smallest, non-zero number would be = .0625 CSC 370 (Blum)

42 Floating point representation
Floating point representation allows one to represent a wider range of numbers using the same number of bits. It is like scientific notation. CSC 370 (Blum)

43 Scientific notation Used to represent very large and very small numbers Ex. Avogadro’s number   1023 particles Ex. Fundamental charge e   C  C CSC 370 (Blum)

44 Scientific notation: all of these are the same number
=  100  10 =  101  100 =  102  103  104 Rule: Shift the point to the left and increment the power of ten. CSC 370 (Blum)

45 Small numbers  10-1  10-2  10-3  10-4  10-5 1.234  10-6 Rule: shift point to the right and decrement the power. CSC 370 (Blum)

46 Floating Point Rules Starting with the fixed point binary representation, shift the point and increase the power (of 2 now that we’re in binary) Shift so that the number has no whole number part and also so that the first fractional bit (the half’s place) has a 1. CSC 370 (Blum)

47 Floats SHIFT expression so it is just under 1 and keep track of the number of shifts  27 Express the number of shifts in binary CSC 370 (Blum)

48 Mantissa and Exponent and Sign
(Significand) Mantissa Exponent The number may be negative, so there a bit (the sign bit) reserved to indicate whether the number is positive or negative CSC 370 (Blum)

49 Small numbers  2-4 The power (a.k.a. the exponent) could be negative so we have to be able to deal with that. Floating point numbers use a procedure known as biasing to handle the negative exponent problem. CSC 370 (Blum)

50 Biasing Actually the exponent is not represented as shown on the previous slide There were 8 bits used to represent the exponent on the previous slide, that means there are 256 numbers that could be represented Since the exponent could be negative (to represent numbers less than 1), we choose half of the range to be positive and half to be negative , i.e to 127 CSC 370 (Blum)

51 Biasing (Cont.) In biasing, one does not use 2’s complement or a sign bit. Instead one adds a bias (equal to the magnitude of the most negative number) to the exponents and represents the result of that addition. CSC 370 (Blum)

52 Biasing (Cont.) With 8 bits, the bias is 128.
We had to shift 7 times to the left, corresponding to an exponent of +7 We add that to the bias 128+7=135 That is the number we put in the exponent portion: CSC 370 (Blum)

53 Big floats Assume we use 8 bits, 4 for the mantissa and 4 for the exponent (neglecting sign). What is the largest float? Mantissa: Exponent 1111  27 =120 (Compare this to the largest fixed-point number using the same amount of space ) CSC 370 (Blum)

54 Small floats Assume we use 8 bits, 4 for the mantissa and 4 for the exponent (neglecting sign). What is the smalles float? Mantissa: Exponent 0000 0.5  2-8 = (Compare this to the smallest fixed-point number using the same amount of space .0625) CSC 370 (Blum)

55 One more fine point As discussed so far, the mantissa (significand) always starts with a 1. When storage was expensive, designers opted not to represent this bit, since it is always 1. It had to be inserted for various operations on the number (adding, multiplying, etc.), but it did not have to be stored. CSC 370 (Blum)

56 Still another fine point
When we assume that the mantissa must start with a 1, we lose 0. Zero is too important a number to lose, so we interpret the mantissa of all zeros and exponent of all zeros as zero Even though ordinarily we would assume the mantissa started with a one that we didn’t store. CSC 370 (Blum)

57 Yet another fine point In the IEEE 754 format for floats, you bias by one less (127) and reserve the exponents and for special purposes. One on these special purposes is “Not a number” (NaN) which is the floating point version of overflow. CSC 370 (Blum)


Download ppt "Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)"

Similar presentations


Ads by Google