SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
1
1
Today: Integer Arithmetic
(H&H 5.1-5.2)
Next: Floating Point Arithmetic
(H&H 5.3)
Lecture Topics
2
Self-study module #4
Project #4 (due no later than 9/26)
Project #5 (due no later than 10/3)
Announcements
2
3
Arithmetic operations:
NEG (negation)
ADD (addition)
SUB (subtraction)
MUL (multiplication)
DIV (division)
Negation is a unary operation (one operand)
Operations on Integers
4
Bitwise operations:
NOT
AND
OR
XOR
NOT is a unary operation (one operand)
Operations on Integers
3
5
Shift operations:
SLL (shift left logical)
SRL (shift right logical)
SRA (shift right arithmetic)
No need for “shift left arithmetic” – same as
“shift left logical”
Operations on Integers
6
Math unit:
addition and subtraction
bitwise operations
Shift unit:
shift operations
Multiply and Divide unit:
multiplication and division
Integer Circuits
4
7
C/C++ shift operations:
SLL <<
SRL >> (when value is unsigned)
SRA >> (when value is signed)
Example: examine an integer value and
count the number of bits which are 1s
(C source code on next slide).
Bitwise Operators in C/C++
8
#include <stdio.h>
int main()
{
unsigned int i, n, val = 0x7890ABCD;
for (i=0; i<32; i++)
{
n = n + ((val >> i) & 0x00000001);
}
printf( "value: %08x count: %dn", val, n );
return 0;
}
value: 7890abcd count: 16
5
9
Logarithmic barrel shifter: for N bit register,
use log2 N levels of multiplexers
Example: 8 bit register ==> 3 levels
1st level – shift 4 bits
2nd level – shift 2 bits
3rd level – shift 1 bit
Shift Circuits
10
Right Logical Shifter (8 bits)
6
11
Control signal (2 bits):
No shift
Shift left logical
Shift right logical
Shift right arithmetic
Combined Shift Circuits
12
Require several steps
Simple versions use sequential logic
Multiply: N bits X N bits ==> 2N bits
Divide: 2N bits / N bits ==> N bits
Multiplication and Division
7
13
Example: 4 bits X 4 bits ==> 8 bits
1101 Multiplicand
MUL 1011 Multiplier
--------
1101 Partial products
1101
0000
1101
--------
10001111 Product
Unsigned Multiplication
14
Unsigned Serial Multiplication
8
15
Unsigned Serial Division
16
Serial multiply (and divide) require sequence
of steps
Signed multiply (and divide) must account
for sign bits
More complex circuits can reduce number of
steps
Summary
9
17
C is the parent of C++ (and thus a subset)
C++ features which are not part of C:
Classes (and thus no I/O classes)
Templates (and thus no STL)
One other minor difference: C does not
support local variables in "for" statements
for (int i=0; i<10; i++) // illegal
Programming in C
18
No classes, so no stream class library.
Thus, all I/O must be done via functions.
Example:
printf( "Sum: %dn", total );
Rich set of functions in the standard library;
most programmers only use a few.
I/O in C
10
19
Standard Streams
Monitor
Executing
program
Keyboard
stdoutstdin
Output DeviceInput Device
stdin – standard input stream
stdout – standard output stream
20
File Streams
Executing
program
file object file object
OutputInput
Function fopen() used to create a file object, interact
with the operating system's file system.
File (on disk)File (on disk)
11
21
Returns one character (one byte, converted to four
bytes) from the standard input stream. Returns -1
when end-of-file is true.
int getchar();
Sends one character (four bytes, converted to one
byte) into the standard output stream. Returns a
copy of the character (-1, if an error occurs).
int putchar( int );
Character I/O
22
#include <stdio.h>
int main()
{
int input;
for (;;)
{
input = getchar();
if (input == EOF) break;
putchar( input );
}
return 0;
}
12
23
Translate (compile and link) the program. Then,
execute it and supply input from the keyboard.
<2 north:~/Examples > gcc -Wall example08.c
<3 north:~/Examples > a.out
This is the first line.
This is the first line.
And this is the last line.
And this is the last line.
^D
24
Execute it again and use input redirection to
supply input from a file.
<4 north:~/Examples > a.out < example08.c
/*********************************************************
Example #2 -- Demo the use of "getchar" and "putchar"
*********************************************************/
#include <stdio.h>
int main()
{
int input;
...
(entire contents of the file, character-by-character)
13
25
I/O Buffering (input stream)
Executing
program
OS
Function getchar() waits until the buffer is not empty,
fetches the next character and updates the pointer to the
current item. OS routines fill the buffer when it is empty.
File (on disk)
F
i
r
s
t
l
…
getchar()
26
I/O Buffering (input stream)
Executing
program
OS
The only difference with the standard input stream: the
OS routines echo print the characters as they are copied
into the buffer. Copying a newline signals "buffer ready".
Keyboard
F
i
r
s
t
l
…
getchar()
14
27
I/O Buffering (output stream)
Executing
program
OS
Function putchar() waits until there is room in the
buffer, then stores the next character and updates the
pointer to the current item. OS routines empty the buffer
when it is full.
File (on disk)
S
o
m
e
o
u
…
putchar()
28
I/O Buffering (output stream)
Executing
program
OS
No significant difference with the standard output stream
(some output functions flush the buffer themselves, such
as the endl manipulator in C++).
monitor
S
o
m
e
o
u
…
putchar()
15
29
Reads characters from the standard input stream,
converts substrings according to the format string.
Returns the number of successful conversions.
int scanf( const char *form, ... );
Converts items into characters strings according to
the format string, sends them to the standard output
stream. Returns the number of characters sent.
int printf( const char *form, ... );
Formatted I/O
30
int main()
{
const char A = '?';
const short B = 19;
const int C = 28;
printf( "A: %2c %2d %xnn", A, A, A );
printf( "B: %2d %2x %04xnn", B, B, B );
printf( "C: %2d %2X %08Xnn", C, C, C );
}
A: ? 63 3f
B: 19 13 0013
C: 28 1C 0000001C
16
31
int main()
{
const float D = 23.5;
const double E = 16.25;
const char F[] = "CSE 320";
printf( "D: %f %5.2f %e %6.4enn", D, D, D, D );
printf( "E: %f %5.2f %E %6.4Enn", E, E, E, E );
printf( "F: >%s< >%10s< >%-10s<nn", F, F, F );
}
D: 23.500000 23.50 2.350000e+01 2.3500e+01
E: 16.250000 16.25 1.625000E+01 1.6250E+01
F: >CSE 320< > CSE 320< >CSE 320 <
32
int main()
{
int Count, X;
double Y;
char Z;
printf( "Enter an integer, a real and a char: " );
Count = scanf( "%d %lf %c", &X, &Y, &Z );
if (Count > 0)
{
printf( "X: %d Y: %g Z: %cnn", X, Y, Z );
}
}
Enter an integer, a real and a char: 125 7.5e-3 A
X: 125 Y: 0.0075 Z: A
17
33
Function printf() converts items from internal
representation into character strings (based on the
formatting specs) and copies them into the output
buffer.
%c – put character
%s – put character(s), stop on null byte
%d – put decimal digit(s)
%x – put hex digit(s)
Note: printf() is converting internal
representation to external represenation.
34
Example:
short int N = 67;
printf( "N: %d %x %cn", N, N, N );
N in RAM: 0000000001000011
Output buffer:
. . . n N : 6 7 4 3 C n .
Old New
18
35
Function scanf() extracts characters from the
input buffer, converts them based on the formatting
specs and stores them in memory at the pointers.
%c – get character
%s – get character(s), stop on whitespace
%d – get decimal digit(s), stop on anything else
%x – get hex digit(s), stop on anything else
Function skips leading whitespace; handles special
cases gracefully (ex: formatting spec is %d, next
character is not a decimal digit).
36
Example:
Count = scanf( "%d %x %c", &X, &Y, &Z );
Input buffer:
%d – extracts " 125", converts to two's complement
%x – extracts " 7af", converts to two's complement
%c – extracts " A" (no conversion necessary)
Buffer pointer now is positioned on "B"
. 1 2 5 7 a f A B C .
Old New
19
37
Conversion: external base 10 to internal
"125" ==> 0000000001111101 (16 bits)
Calculation:
125 = 1 * 102 + 2 * 101 + 5 * 100
Processing characters:
(“1”-“0”) * 102 + (“2”-“0”) * 101 + (“5”-“0”) * 100
Note: “5”-“0” = 53 – 48 = 5
38
Conversion: external base 16 to internal
"7af" ==> 0000011110101111 (16 bits)
Calculation:
7af = 7 * 162 + a * 161 + f * 160
Processing characters:
(“7”-“0”) * 162 + (“a”-“a”+10) * 161 + (“f”-“a”+10)
Note: “f”-“a”+10 = 102 – 97 + 10 = 15
20
39
Nested calculation:
125 = 1 * 102 + 2 * 101 + 5 * 100
= (((((1) * 10) + 2) * 10) + 5)
7af = 7 * 162 + a * 161 + f * 160
= (((((7) * 16) + a) * 16) + f )
40
Algorithm:
answer = 0
iterate over digits in original number
answer = answer * base + current digit
Programming considerations:
digits must be converted from char to int
all values in two’s complement inside circuits
21
41
Conversion: internal to external base 10
0000000001000011 (16 bits) ==> "67"
Calculation:
67 / 10 = 6 R 7
6 / 10 = 0 R 6 (halt when quotient is 0)
Process digits from bottom to top, convert each digit
to the corresponding character.
Note: 6 + “0” = “6”
42
Conversion: internal to external base 16
0000000001000011 (16 bits) ==> "43"
Calculation:
67 / 16 = 4 R 3
4 / 16 = 0 R 4 (halt when quotient is 0)
Process digits from bottom to top, convert each digit
to the corresponding character.
Note: 4 + “0” = “4”
22
43
Algorithm:
value = original number
loop until value == 0
current digit = value % base
value = value / base
Programming considerations:
digits generated in reverse order
digits must be converted from int to char
all values in two’s complement inside circuits
44
Complete examples:
~cse320/Examples/example08.pdf
~cse320/Examples/example09.pdf
1
1
Today: Floating Point Arithmetic
(H&H 5.3)
Next: continued
Lecture Topics
2
Self-study Module #5 (this week)
Project #5 (due no later than 10/3)
Project #6 (due no later than 10/17)
Exam #1 – Thursday, 10/10
Announcements
2
3
Thursday, 10/10 during lecture
18% of course grade
Bring #2 pencils (multiple choice)
Bring MSU ID
One 8.5x11 note sheet (both sides)
Old exam on course website
Exam #1
4
In mathematics, the real numbers are infinite and
continuous.
In computing, the floating point numbers are finite
and discrete because there is a fixed number of
bits to represent values.
N bits ==> 2N bit patterns
Floating point values are a subset of the real
numbers.
Floating Point Numbers
3
5
Single precision: 32 bits (4 bytes)
Double precision: 64 bits (8 bytes)
IEEE-754 Floating Point Formats
6
value double precision single precision
----- ---------------- ----------------
+inf 7FF0000000000000 7F800000
+99.5 4058E00000000000 42C70000
+15.0 402E000000000000 41700000
+10.75 4025800000000000 412C0000
+10.5 4025000000000000 41280000
+10.0 4024000000000000 41200000
+3.3 400A666666666666 40533333
+3.25 400A000000000000 40500000
+3.0 4008000000000000 40400000
+2.1 4000CCCCCCCCCCCD 40066666
+1.5 3FF8000000000000 3FC00000
+1.25 3FF4000000000000 3FA00000
+1.0 3FF0000000000000 3F800000
+0.5 3FE0000000000000 3F000000
+0.25 3FD0000000000000 3E800000
+0.0 0000000000000000 00000000
-0.0 8000000000000000 80000000
4
7
Format:
sign of fraction 1 bit
biased exponent 11 bits
fraction 52 bits
Interpretation:
+/- 1.fraction x 2(biased exponent – 0x3FF)
Double Precision
8
Interpretation:
+/- 1.fraction x 2(biased exponent – 0x3FF)
sign: 0 for positive, 1 for negative
significand: 1.fraction
true exponent: biased exponent – 0x3FF
Double Precision
5
9
The decoding process:
Partition the 64 bits into the three fields
Calculate the true exponent
Use the sign, significand and true
exponent to calculate the value
Decoding DP Values
10
Internal rep: 3FFE000000000000 base 16
0011 1111 1111 1110 0000 0000 .... 0000 0000
sign bit: 0 (positive)
biased exponent: 011 1111 1111 (0x3FF)
true exponent: 0x3FF – 0x3FF = 0
significand: 1.111000000000....00000000
value: +1.111 x 20 base 2
= +1.111 base 2
= +1.875 base 10
6
11
Internal rep: C019000000000000 base 16
1100 0000 0001 1001 0000 0000 .... 0000 0000
sign bit: 1 (negative)
biased exponent: 100 0000 0001 (0x401)
true exponent: 0x401 – 0x3FF = 2
significand: 1.100100000000....00000000
value: -1.1001 x 22 base 2
= -110.01 base 2
= -6.25 base 10
12
Internal rep: BFC0000000000000 base 16
1011 1111 1100 0000 0000 0000 .... 0000 0000
sign bit: 1 (negative)
biased exponent: 011 1111 1100 (0x3FC)
true exponent: 0x3FC – 0x3FF = -3
significand: 1.000000000000....00000000
value: -1.0 x 2-3 base 2
= -0.001 base 2
= -0.125 base 10
7
13
The encoding process:
Express the value in binary, then
normalize it
Calculate the biased exponent
Pack the sign, fraction and biased
exponent into the three fields
Encoding DP Values
14
Value: +1.25 base 10
= +1.01 base 2
= +1.01 x 20 base 2
significand: 1.010000000000....00000000
biased exponent: 0x0 + 0x3FF = 0x3FF
= 01111111111
sign bit: 0 (positive)
0011 1111 1111 0100 0000 0000 .... 0000 0000
Internal rep: 3FF4000000000000 base 16
8
15
Value: -10.75 base 10
= -1010.11 base 2
= -1.01011 x 23 base 2
significand: 1.010110000000....00000000
biased exponent: 0x3 + 0x3FF = 0x402
= 10000000010
sign bit: 1 (negative)
1100 0000 0010 0101 1000 0000 .... 0000 0000
Internal rep: C025800000000000 base 16
16
Value: +0.0625 base 10
= +0.0001 base 2
= +1.0 x 2-4 base 2
significand: 1.000000000000....00000000
biased exponent: -0x4 + 0x3FF = 0x3FB
= 01111111011
sign bit: 0 (positive)
0011 1111 1011 0000 0000 0000 .... 0000 0000
Internal rep: 3FB0000000000000 base 16
9
17
Four categories of special values:
Infinity
Not-A-Number
Zero
Denormal Values
All other values called “normalized”
Special Values
18
Biased exponent field all ones
Infinity – fraction field all zeroes
7FF0000000000000
NaN – fraction field not all zeroes
7FF0000000000001
Sign bit can be 1 (for negative); set of 253
different representations of NaN
10
19
Biased exponent field all zeroes
Zero – fraction field all zeroes
0000000000000000
Denormal – fraction field not all zeroes
0000000000000001
Sign bit can be 1 (for negative); set of 253
different denormal values
20
Range of DP exponents:
111 1111 1111 Special (Infinity, NaNs)
111 1111 1110 Largest (+0x3FF or +1023)
...
100 0000 0001 +2
100 0000 0000 +1
011 1111 1111 +0
011 1111 1110 -1
011 1111 1101 -2
...
000 0000 0001 Smallest (-0x3FE or -1022)
000 0000 0000 Special (Zero, Denormals)
11
21
Denormal values are smaller than the
minimal normalized value – they allow us to
have values which are close to zero.
Normalized: 1.fraction x 2(Biased-0x3FF)
Denormal: 0.fraction x 2-0x3FE
All denormal values have the same true
exponent (-0x3FE or -1022)
Denormal (Subnormal) Values
22
The smallest normalized value:
0000000000010000....0000
Value: 1.0 x 2-1022
The largest denormal value:
0000000000001111....1111
Value: 0.1111….1111 x 2-1022
12
23
The second largest denormal value:
0000000000001111....1110
Value: 0.1111….1110 x 2-1022
The smallest denormal value:
0000000000000000....0001
Value: 0.0000….0001 x 2-1022
24
Format:
sign of fraction 1 bit
biased exponent 8 bits
fraction 23 bits
Interpretation:
+/- 1.fraction x 2
(biased exponent – 0x7F)
Single Precision
13
25
Interpretation:
+/- 1.fraction x 2
(biased exponent – 0x7F)
sign: 0 for positive, 1 for negative
significand: 1.fraction
true exponent: biased exponent – 0x7F
Single Precision
26
Range of SP exponents:
1111 1111 Special (Infinity, NaNs)
1111 1110 Largest (+0x7F or +127)
...
1000 0001 +2
1000 0000 +1
0111 1111 +0
0111 1110 -1
0111 1101 -2
...
0000 0001 Smallest (-0x7E or -126)
0000 0000 Special (Zero, Denormals)
14
27
The decoding process is the same as for DP
values, except fields are 1, 8 and 23 bits
The encoding process: sizes of fields
Note: biased exponent field of 8 bits
determines biasing factor:
01111111 = 0x7F
Decoding and Encoding SP Values
28
Internal rep: 40B80000 base 16
0100 0000 1011 1000 0000 0000 0000 0000
sign bit: 0 (positive)
biased exponent: 1000 0001 (0x81)
true exponent: 0x81 – 0x7F = 2
significand: 1.01110000000000000000000
value: +1.0111 x 22 base 2
= +101.11 base 2
= +5.75 base 10
15
29
Internal rep: BFC00000 base 16
1011 1111 1100 0000 0000 0000 0000 0000
sign bit: 1 (negative)
biased exponent: 0111 1111 (0x7F)
true exponent: 0x7F – 0x7F = 0
significand: 1.10000000000000000000000
value: -1.1 x 20 base 2
= -1.1 base 2
= -1.5 base 10
30
Value: +10.75 base 10
= +1010.11 base 2
= +1.01011 x 23 base 2
significand: 1.010110000000....00000000
biased exponent: 0x3 + 0x7F = 0x82
= 10000010
sign bit: 0 (positive)
0100 0001 0010 1100 0000 0000 0000 0000
Internal rep: 412C0000 base 16
16
31
Value: -99.5 base 10
= -1100011.1 base 2
= -1.1000111 x 26 base 2
significand: 1.10001110000000000000000
biased exponent: 0x6 + 0x7F = 0x85
= 10000101
sign bit: 1 (negative)
1100 0010 1100 0111 0000 0000 0000 0000
Internal rep: C2C70000 base 16
32
Goldberg: What Every Computer Scientist
Should Know About Floating-Point Arithmetic
(PDF on the course website)
More depth:

Más contenido relacionado

La actualidad más candente

Simple c program
Simple c programSimple c program
Simple c program
Ravi Singh
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
moduledesign
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
Senthil Kumar
 

La actualidad más candente (20)

Computer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabComputer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlab
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
Simple c program
Simple c programSimple c program
Simple c program
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
Lec15-CS110 Computational Engineering
Lec15-CS110 Computational EngineeringLec15-CS110 Computational Engineering
Lec15-CS110 Computational Engineering
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Booth algorithm
Booth algorithmBooth algorithm
Booth algorithm
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
 
Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
C operators
C operators C operators
C operators
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functions
 
C questions
C questionsC questions
C questions
 
Ansi c
Ansi cAnsi c
Ansi c
 

Similar a Chapter 5

Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 

Similar a Chapter 5 (20)

Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
BKK16-503 Undefined Behavior and Compiler Optimizations – Why Your Program St...
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
operators.ppt
operators.pptoperators.ppt
operators.ppt
 
Cpl
CplCpl
Cpl
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
functions
functionsfunctions
functions
 
C multiple choice questions and answers pdf
C multiple choice questions and answers pdfC multiple choice questions and answers pdf
C multiple choice questions and answers pdf
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Cbasic
CbasicCbasic
Cbasic
 

Más de EasyStudy3 (20)

Week 7
Week 7Week 7
Week 7
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Week 6
Week 6Week 6
Week 6
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
 
Chapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish completeChapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish complete
 
L6
L6L6
L6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
2
22
2
 
Lec#4
Lec#4Lec#4
Lec#4
 
Chapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space mergedChapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space merged
 
Week 5
Week 5Week 5
Week 5
 
Chpater 6
Chpater 6Chpater 6
Chpater 6
 
Lec#3
Lec#3Lec#3
Lec#3
 
Chapter 16 2
Chapter 16 2Chapter 16 2
Chapter 16 2
 
Chapter 5 gen chem
Chapter 5 gen chemChapter 5 gen chem
Chapter 5 gen chem
 
Topic 4 gen chem guobi
Topic 4 gen chem guobiTopic 4 gen chem guobi
Topic 4 gen chem guobi
 
Gen chem topic 3 guobi
Gen chem topic 3  guobiGen chem topic 3  guobi
Gen chem topic 3 guobi
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Gen chem topic 1 guobi
Gen chem topic 1 guobiGen chem topic 1 guobi
Gen chem topic 1 guobi
 
Chapter1 f19 bb(1)
Chapter1 f19 bb(1)Chapter1 f19 bb(1)
Chapter1 f19 bb(1)
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Último (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Chapter 5

  • 1. 1 1 Today: Integer Arithmetic (H&H 5.1-5.2) Next: Floating Point Arithmetic (H&H 5.3) Lecture Topics 2 Self-study module #4 Project #4 (due no later than 9/26) Project #5 (due no later than 10/3) Announcements
  • 2. 2 3 Arithmetic operations: NEG (negation) ADD (addition) SUB (subtraction) MUL (multiplication) DIV (division) Negation is a unary operation (one operand) Operations on Integers 4 Bitwise operations: NOT AND OR XOR NOT is a unary operation (one operand) Operations on Integers
  • 3. 3 5 Shift operations: SLL (shift left logical) SRL (shift right logical) SRA (shift right arithmetic) No need for “shift left arithmetic” – same as “shift left logical” Operations on Integers 6 Math unit: addition and subtraction bitwise operations Shift unit: shift operations Multiply and Divide unit: multiplication and division Integer Circuits
  • 4. 4 7 C/C++ shift operations: SLL << SRL >> (when value is unsigned) SRA >> (when value is signed) Example: examine an integer value and count the number of bits which are 1s (C source code on next slide). Bitwise Operators in C/C++ 8 #include <stdio.h> int main() { unsigned int i, n, val = 0x7890ABCD; for (i=0; i<32; i++) { n = n + ((val >> i) & 0x00000001); } printf( "value: %08x count: %dn", val, n ); return 0; } value: 7890abcd count: 16
  • 5. 5 9 Logarithmic barrel shifter: for N bit register, use log2 N levels of multiplexers Example: 8 bit register ==> 3 levels 1st level – shift 4 bits 2nd level – shift 2 bits 3rd level – shift 1 bit Shift Circuits 10 Right Logical Shifter (8 bits)
  • 6. 6 11 Control signal (2 bits): No shift Shift left logical Shift right logical Shift right arithmetic Combined Shift Circuits 12 Require several steps Simple versions use sequential logic Multiply: N bits X N bits ==> 2N bits Divide: 2N bits / N bits ==> N bits Multiplication and Division
  • 7. 7 13 Example: 4 bits X 4 bits ==> 8 bits 1101 Multiplicand MUL 1011 Multiplier -------- 1101 Partial products 1101 0000 1101 -------- 10001111 Product Unsigned Multiplication 14 Unsigned Serial Multiplication
  • 8. 8 15 Unsigned Serial Division 16 Serial multiply (and divide) require sequence of steps Signed multiply (and divide) must account for sign bits More complex circuits can reduce number of steps Summary
  • 9. 9 17 C is the parent of C++ (and thus a subset) C++ features which are not part of C: Classes (and thus no I/O classes) Templates (and thus no STL) One other minor difference: C does not support local variables in "for" statements for (int i=0; i<10; i++) // illegal Programming in C 18 No classes, so no stream class library. Thus, all I/O must be done via functions. Example: printf( "Sum: %dn", total ); Rich set of functions in the standard library; most programmers only use a few. I/O in C
  • 10. 10 19 Standard Streams Monitor Executing program Keyboard stdoutstdin Output DeviceInput Device stdin – standard input stream stdout – standard output stream 20 File Streams Executing program file object file object OutputInput Function fopen() used to create a file object, interact with the operating system's file system. File (on disk)File (on disk)
  • 11. 11 21 Returns one character (one byte, converted to four bytes) from the standard input stream. Returns -1 when end-of-file is true. int getchar(); Sends one character (four bytes, converted to one byte) into the standard output stream. Returns a copy of the character (-1, if an error occurs). int putchar( int ); Character I/O 22 #include <stdio.h> int main() { int input; for (;;) { input = getchar(); if (input == EOF) break; putchar( input ); } return 0; }
  • 12. 12 23 Translate (compile and link) the program. Then, execute it and supply input from the keyboard. <2 north:~/Examples > gcc -Wall example08.c <3 north:~/Examples > a.out This is the first line. This is the first line. And this is the last line. And this is the last line. ^D 24 Execute it again and use input redirection to supply input from a file. <4 north:~/Examples > a.out < example08.c /********************************************************* Example #2 -- Demo the use of "getchar" and "putchar" *********************************************************/ #include <stdio.h> int main() { int input; ... (entire contents of the file, character-by-character)
  • 13. 13 25 I/O Buffering (input stream) Executing program OS Function getchar() waits until the buffer is not empty, fetches the next character and updates the pointer to the current item. OS routines fill the buffer when it is empty. File (on disk) F i r s t l … getchar() 26 I/O Buffering (input stream) Executing program OS The only difference with the standard input stream: the OS routines echo print the characters as they are copied into the buffer. Copying a newline signals "buffer ready". Keyboard F i r s t l … getchar()
  • 14. 14 27 I/O Buffering (output stream) Executing program OS Function putchar() waits until there is room in the buffer, then stores the next character and updates the pointer to the current item. OS routines empty the buffer when it is full. File (on disk) S o m e o u … putchar() 28 I/O Buffering (output stream) Executing program OS No significant difference with the standard output stream (some output functions flush the buffer themselves, such as the endl manipulator in C++). monitor S o m e o u … putchar()
  • 15. 15 29 Reads characters from the standard input stream, converts substrings according to the format string. Returns the number of successful conversions. int scanf( const char *form, ... ); Converts items into characters strings according to the format string, sends them to the standard output stream. Returns the number of characters sent. int printf( const char *form, ... ); Formatted I/O 30 int main() { const char A = '?'; const short B = 19; const int C = 28; printf( "A: %2c %2d %xnn", A, A, A ); printf( "B: %2d %2x %04xnn", B, B, B ); printf( "C: %2d %2X %08Xnn", C, C, C ); } A: ? 63 3f B: 19 13 0013 C: 28 1C 0000001C
  • 16. 16 31 int main() { const float D = 23.5; const double E = 16.25; const char F[] = "CSE 320"; printf( "D: %f %5.2f %e %6.4enn", D, D, D, D ); printf( "E: %f %5.2f %E %6.4Enn", E, E, E, E ); printf( "F: >%s< >%10s< >%-10s<nn", F, F, F ); } D: 23.500000 23.50 2.350000e+01 2.3500e+01 E: 16.250000 16.25 1.625000E+01 1.6250E+01 F: >CSE 320< > CSE 320< >CSE 320 < 32 int main() { int Count, X; double Y; char Z; printf( "Enter an integer, a real and a char: " ); Count = scanf( "%d %lf %c", &X, &Y, &Z ); if (Count > 0) { printf( "X: %d Y: %g Z: %cnn", X, Y, Z ); } } Enter an integer, a real and a char: 125 7.5e-3 A X: 125 Y: 0.0075 Z: A
  • 17. 17 33 Function printf() converts items from internal representation into character strings (based on the formatting specs) and copies them into the output buffer. %c – put character %s – put character(s), stop on null byte %d – put decimal digit(s) %x – put hex digit(s) Note: printf() is converting internal representation to external represenation. 34 Example: short int N = 67; printf( "N: %d %x %cn", N, N, N ); N in RAM: 0000000001000011 Output buffer: . . . n N : 6 7 4 3 C n . Old New
  • 18. 18 35 Function scanf() extracts characters from the input buffer, converts them based on the formatting specs and stores them in memory at the pointers. %c – get character %s – get character(s), stop on whitespace %d – get decimal digit(s), stop on anything else %x – get hex digit(s), stop on anything else Function skips leading whitespace; handles special cases gracefully (ex: formatting spec is %d, next character is not a decimal digit). 36 Example: Count = scanf( "%d %x %c", &X, &Y, &Z ); Input buffer: %d – extracts " 125", converts to two's complement %x – extracts " 7af", converts to two's complement %c – extracts " A" (no conversion necessary) Buffer pointer now is positioned on "B" . 1 2 5 7 a f A B C . Old New
  • 19. 19 37 Conversion: external base 10 to internal "125" ==> 0000000001111101 (16 bits) Calculation: 125 = 1 * 102 + 2 * 101 + 5 * 100 Processing characters: (“1”-“0”) * 102 + (“2”-“0”) * 101 + (“5”-“0”) * 100 Note: “5”-“0” = 53 – 48 = 5 38 Conversion: external base 16 to internal "7af" ==> 0000011110101111 (16 bits) Calculation: 7af = 7 * 162 + a * 161 + f * 160 Processing characters: (“7”-“0”) * 162 + (“a”-“a”+10) * 161 + (“f”-“a”+10) Note: “f”-“a”+10 = 102 – 97 + 10 = 15
  • 20. 20 39 Nested calculation: 125 = 1 * 102 + 2 * 101 + 5 * 100 = (((((1) * 10) + 2) * 10) + 5) 7af = 7 * 162 + a * 161 + f * 160 = (((((7) * 16) + a) * 16) + f ) 40 Algorithm: answer = 0 iterate over digits in original number answer = answer * base + current digit Programming considerations: digits must be converted from char to int all values in two’s complement inside circuits
  • 21. 21 41 Conversion: internal to external base 10 0000000001000011 (16 bits) ==> "67" Calculation: 67 / 10 = 6 R 7 6 / 10 = 0 R 6 (halt when quotient is 0) Process digits from bottom to top, convert each digit to the corresponding character. Note: 6 + “0” = “6” 42 Conversion: internal to external base 16 0000000001000011 (16 bits) ==> "43" Calculation: 67 / 16 = 4 R 3 4 / 16 = 0 R 4 (halt when quotient is 0) Process digits from bottom to top, convert each digit to the corresponding character. Note: 4 + “0” = “4”
  • 22. 22 43 Algorithm: value = original number loop until value == 0 current digit = value % base value = value / base Programming considerations: digits generated in reverse order digits must be converted from int to char all values in two’s complement inside circuits 44 Complete examples: ~cse320/Examples/example08.pdf ~cse320/Examples/example09.pdf
  • 23. 1 1 Today: Floating Point Arithmetic (H&H 5.3) Next: continued Lecture Topics 2 Self-study Module #5 (this week) Project #5 (due no later than 10/3) Project #6 (due no later than 10/17) Exam #1 – Thursday, 10/10 Announcements
  • 24. 2 3 Thursday, 10/10 during lecture 18% of course grade Bring #2 pencils (multiple choice) Bring MSU ID One 8.5x11 note sheet (both sides) Old exam on course website Exam #1 4 In mathematics, the real numbers are infinite and continuous. In computing, the floating point numbers are finite and discrete because there is a fixed number of bits to represent values. N bits ==> 2N bit patterns Floating point values are a subset of the real numbers. Floating Point Numbers
  • 25. 3 5 Single precision: 32 bits (4 bytes) Double precision: 64 bits (8 bytes) IEEE-754 Floating Point Formats 6 value double precision single precision ----- ---------------- ---------------- +inf 7FF0000000000000 7F800000 +99.5 4058E00000000000 42C70000 +15.0 402E000000000000 41700000 +10.75 4025800000000000 412C0000 +10.5 4025000000000000 41280000 +10.0 4024000000000000 41200000 +3.3 400A666666666666 40533333 +3.25 400A000000000000 40500000 +3.0 4008000000000000 40400000 +2.1 4000CCCCCCCCCCCD 40066666 +1.5 3FF8000000000000 3FC00000 +1.25 3FF4000000000000 3FA00000 +1.0 3FF0000000000000 3F800000 +0.5 3FE0000000000000 3F000000 +0.25 3FD0000000000000 3E800000 +0.0 0000000000000000 00000000 -0.0 8000000000000000 80000000
  • 26. 4 7 Format: sign of fraction 1 bit biased exponent 11 bits fraction 52 bits Interpretation: +/- 1.fraction x 2(biased exponent – 0x3FF) Double Precision 8 Interpretation: +/- 1.fraction x 2(biased exponent – 0x3FF) sign: 0 for positive, 1 for negative significand: 1.fraction true exponent: biased exponent – 0x3FF Double Precision
  • 27. 5 9 The decoding process: Partition the 64 bits into the three fields Calculate the true exponent Use the sign, significand and true exponent to calculate the value Decoding DP Values 10 Internal rep: 3FFE000000000000 base 16 0011 1111 1111 1110 0000 0000 .... 0000 0000 sign bit: 0 (positive) biased exponent: 011 1111 1111 (0x3FF) true exponent: 0x3FF – 0x3FF = 0 significand: 1.111000000000....00000000 value: +1.111 x 20 base 2 = +1.111 base 2 = +1.875 base 10
  • 28. 6 11 Internal rep: C019000000000000 base 16 1100 0000 0001 1001 0000 0000 .... 0000 0000 sign bit: 1 (negative) biased exponent: 100 0000 0001 (0x401) true exponent: 0x401 – 0x3FF = 2 significand: 1.100100000000....00000000 value: -1.1001 x 22 base 2 = -110.01 base 2 = -6.25 base 10 12 Internal rep: BFC0000000000000 base 16 1011 1111 1100 0000 0000 0000 .... 0000 0000 sign bit: 1 (negative) biased exponent: 011 1111 1100 (0x3FC) true exponent: 0x3FC – 0x3FF = -3 significand: 1.000000000000....00000000 value: -1.0 x 2-3 base 2 = -0.001 base 2 = -0.125 base 10
  • 29. 7 13 The encoding process: Express the value in binary, then normalize it Calculate the biased exponent Pack the sign, fraction and biased exponent into the three fields Encoding DP Values 14 Value: +1.25 base 10 = +1.01 base 2 = +1.01 x 20 base 2 significand: 1.010000000000....00000000 biased exponent: 0x0 + 0x3FF = 0x3FF = 01111111111 sign bit: 0 (positive) 0011 1111 1111 0100 0000 0000 .... 0000 0000 Internal rep: 3FF4000000000000 base 16
  • 30. 8 15 Value: -10.75 base 10 = -1010.11 base 2 = -1.01011 x 23 base 2 significand: 1.010110000000....00000000 biased exponent: 0x3 + 0x3FF = 0x402 = 10000000010 sign bit: 1 (negative) 1100 0000 0010 0101 1000 0000 .... 0000 0000 Internal rep: C025800000000000 base 16 16 Value: +0.0625 base 10 = +0.0001 base 2 = +1.0 x 2-4 base 2 significand: 1.000000000000....00000000 biased exponent: -0x4 + 0x3FF = 0x3FB = 01111111011 sign bit: 0 (positive) 0011 1111 1011 0000 0000 0000 .... 0000 0000 Internal rep: 3FB0000000000000 base 16
  • 31. 9 17 Four categories of special values: Infinity Not-A-Number Zero Denormal Values All other values called “normalized” Special Values 18 Biased exponent field all ones Infinity – fraction field all zeroes 7FF0000000000000 NaN – fraction field not all zeroes 7FF0000000000001 Sign bit can be 1 (for negative); set of 253 different representations of NaN
  • 32. 10 19 Biased exponent field all zeroes Zero – fraction field all zeroes 0000000000000000 Denormal – fraction field not all zeroes 0000000000000001 Sign bit can be 1 (for negative); set of 253 different denormal values 20 Range of DP exponents: 111 1111 1111 Special (Infinity, NaNs) 111 1111 1110 Largest (+0x3FF or +1023) ... 100 0000 0001 +2 100 0000 0000 +1 011 1111 1111 +0 011 1111 1110 -1 011 1111 1101 -2 ... 000 0000 0001 Smallest (-0x3FE or -1022) 000 0000 0000 Special (Zero, Denormals)
  • 33. 11 21 Denormal values are smaller than the minimal normalized value – they allow us to have values which are close to zero. Normalized: 1.fraction x 2(Biased-0x3FF) Denormal: 0.fraction x 2-0x3FE All denormal values have the same true exponent (-0x3FE or -1022) Denormal (Subnormal) Values 22 The smallest normalized value: 0000000000010000....0000 Value: 1.0 x 2-1022 The largest denormal value: 0000000000001111....1111 Value: 0.1111….1111 x 2-1022
  • 34. 12 23 The second largest denormal value: 0000000000001111....1110 Value: 0.1111….1110 x 2-1022 The smallest denormal value: 0000000000000000....0001 Value: 0.0000….0001 x 2-1022 24 Format: sign of fraction 1 bit biased exponent 8 bits fraction 23 bits Interpretation: +/- 1.fraction x 2 (biased exponent – 0x7F) Single Precision
  • 35. 13 25 Interpretation: +/- 1.fraction x 2 (biased exponent – 0x7F) sign: 0 for positive, 1 for negative significand: 1.fraction true exponent: biased exponent – 0x7F Single Precision 26 Range of SP exponents: 1111 1111 Special (Infinity, NaNs) 1111 1110 Largest (+0x7F or +127) ... 1000 0001 +2 1000 0000 +1 0111 1111 +0 0111 1110 -1 0111 1101 -2 ... 0000 0001 Smallest (-0x7E or -126) 0000 0000 Special (Zero, Denormals)
  • 36. 14 27 The decoding process is the same as for DP values, except fields are 1, 8 and 23 bits The encoding process: sizes of fields Note: biased exponent field of 8 bits determines biasing factor: 01111111 = 0x7F Decoding and Encoding SP Values 28 Internal rep: 40B80000 base 16 0100 0000 1011 1000 0000 0000 0000 0000 sign bit: 0 (positive) biased exponent: 1000 0001 (0x81) true exponent: 0x81 – 0x7F = 2 significand: 1.01110000000000000000000 value: +1.0111 x 22 base 2 = +101.11 base 2 = +5.75 base 10
  • 37. 15 29 Internal rep: BFC00000 base 16 1011 1111 1100 0000 0000 0000 0000 0000 sign bit: 1 (negative) biased exponent: 0111 1111 (0x7F) true exponent: 0x7F – 0x7F = 0 significand: 1.10000000000000000000000 value: -1.1 x 20 base 2 = -1.1 base 2 = -1.5 base 10 30 Value: +10.75 base 10 = +1010.11 base 2 = +1.01011 x 23 base 2 significand: 1.010110000000....00000000 biased exponent: 0x3 + 0x7F = 0x82 = 10000010 sign bit: 0 (positive) 0100 0001 0010 1100 0000 0000 0000 0000 Internal rep: 412C0000 base 16
  • 38. 16 31 Value: -99.5 base 10 = -1100011.1 base 2 = -1.1000111 x 26 base 2 significand: 1.10001110000000000000000 biased exponent: 0x6 + 0x7F = 0x85 = 10000101 sign bit: 1 (negative) 1100 0010 1100 0111 0000 0000 0000 0000 Internal rep: C2C70000 base 16 32 Goldberg: What Every Computer Scientist Should Know About Floating-Point Arithmetic (PDF on the course website) More depth: