Announcements Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit Quiz 2 Monday on Number System Conversions Covers lectures on computer number systems Covers all types of problems in Homework 1 Try practice problems (posted to class schedule) CSC 242 - Computer Organization 1
Representing Real Numbers: Floating Point Finale CSC 242 Computer Organization Dr. Lucas Layman January 31, 2018
IEEE 754 Standard for Floating-Point Arithmetic Defines a different format for storing real numbers Specify rules for communicating real numbers between components Rounding rules Arithmetic operations Exception handling (division by zero, overflow, etc) CSC 242 - Computer Organization 3
IEEE 754 generalized process 1) Convert the integer and significand from decimal to binary 2) Normalize the binary, a.k.a., convert it to scientific notation in binary 3) Store the key values of the normalized binary this is the floating point representation CSC 242 - Computer Organization 4
1) Convert the integer and significand from decimal to binary Example: convert 2.625 10 to 8-bit binary Algorithm: a) Convert the integer part (2) to binary using successive division. b) Convert the significand (.625) to binary using successive multiplication: 1) Multiply only the significand by 2 2) Note the integer value (1 or 0). These are your binary significands starting with the MSB. 3) Repeat steps 1-2 until your significand is 0 or you hit the maximum number of bits c) Write the binary CSC 242 - Computer Organization 5
2) Normalize the binary Move the radix point so that it is one bit from the left. Adjust the exponent so that the value does not change. 2.625 10 = 10.101000 2 = 0.40625 10 = 0.01101 2 = 3.14159 10 = 11.001001 2 = CSC 242 - Computer Organization 6
3) Store the key values of the normalized binary 1) the sign 3) the exponent 3.14 10 = ±1.1001001 x 2 1 2) the significand CSC 242 - Computer Organization 7
3) Store the key values of the normalized binary exponent 3 bits An 8-bit float (1 byte): 0 1 1 0 1 1 1 1 sign bit significand 4 bits Note: 8-bit floats aren t very useful, but they illustrate the process. Modern computers use 32- and 64-bit floats. CSC 242 - Computer Organization 8
3) Store the key values of the normalized binary (cont.) 3.14159 10 = +1.1001001 x 2 1 exponent 3 bits Sign bit: 1 = negative, 0 = non-negative Exponent bits: sign bit Take the exponent and add the bias to it. The bias is always 2 k-1-1 where k is the number of bits in the exponent field. Convert the exponent (with added bias) to binary. Significand bits: take the first m bits of your normalized binary s significand significand 4 bits CSC 242 - Computer Organization 9
3) Store the key values of the normalized binary (cont.) 3.14159 10 = ±1.1001001 x 2 1 exponent 3 bits Sign bit: Exponent bits: We have dropped this 1. It is implied. sign bit mantissa 4 bits Significand bits: CSC 242 - Computer Organization 10
3) Store the key values of the normalized binary (cont.) -0.40625 10 = 1.10100 x 2-2 exponent 3 bits Sign bit: Exponent bits: We have dropped this 1. It is implied. sign bit significand 4 bits Significand bits: CSC 242 - Computer Organization 11
Once more, beginning to end Convert -14.6875 to 8-bit IEEE 754 floating point 1) 14.6875 to binary: 2) Normalize: 3) Store values: 1) Sign bit: 2) Exponent: 3) Significand: Answer: exponent 3 bits sign bit significand 4 bits CSC 242 - Computer Organization 12
Floats in modern computers A single-precision float is 4 bytes, or 32 bits: exponent 8 bits 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 1 0 1 1 1 1 sign bit significand 23 bits CSC 242 - Computer Organization 13
Floats in modern computers (cont.) A double-precision float is 8 bytes, or 64 bits. Python uses this by default. 8 bit 32 bit 64 bit exponent 11 bits significand 52 bits CSC 242 - Computer Organization 14
Converting to IEEE 32-bit floating point format Convert -1313.3125 10 (process is the same as 8-bit) 1) Convert the integer and significand from decimal to binary (example 3) -> 10100100001.0101 2 2) Normalize: 1.01001000010101 x 2 10 3) Store the key values of the normalized binary: Sign bit: 1 Exponent: 10+127 = 137 10 = 10001001 2 Note: The bias for a 32 bit floating point # is always 127 Significand: 01001000010101000000000 CSC 242 - Computer Organization 15
Converting to IEEE 32-bit floating point format (cont.) -1313.3125 10 = Sign bit: 1 Exponent: 10+127 = 137 10 = 10001001 2 Significand: 01001000010101000000000 exponent 8 bits 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 sign bit significand 23 bits CSC 242 - Computer Organization 16
Another 32-bit example Convert -78.5625 10 to 32-bit floating point 1) Convert the integer and significand from decimal to binary 2) Normalize the binary 3) Store the key values of the normalized binary 1) sign bit 2) exponent (remember the bias is 127) 3) the significand to 23 bits CSC 242 - Computer Organization 17
Review on computer representations of numbers Name Base Range Purpose Decimal 10 [0,9] The number system most humans use Binary 2 [0,1] The language of all computers Octal 8 [0,7] Rarely used. Common in early computers Hex 16 [0,F] user-friendly representation of binary data CSC 242 - Computer Organization 18
Review on computer representations of numbers Name Base Purpose Two s complement 2 A way to represent signed integers Floating point Any A way to represent real numbers CSC 242 - Computer Organization 19
Storing other types of data We ve discussed storing integers and real numbers But binary bits/bytes can also store: Pixel data for images (e.g., color codes) Digital audio (e.g., compressed or uncompressed waveforms) Program instructions (e.g., from Python or Java) Alphabet characters for display on the monitor Everything is stored in binary, but what the binary represents depends on how the binary is used CSC 242 - Computer Organization 20
One example ASCII ASCII American Standard Code for Information Interchange 128 characters (including null) represented by 2 7 bits. Characters are usually referred to by their 2-digit hex: 00-7F. Developed in the 60 s when Bell telephone created a digital telegraph CSC 242 - Computer Organization 21
CSC 242 - Computer Organization 22
Unicode There are other characters than in ASCII Unicode consortium handles all the characters in the world. Unicode specifies the international standard for representing characters, including emojis CSC 242 - Computer Organization 23