1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.

Slides:



Advertisements
Similar presentations
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Advertisements

DAT2343 Summary of Standard Data Encoding © Alan T. Pinck / Algonquin College; 2003.
Lecture - 2 Number systems and computer data formats
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Floating Point Numbers
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.
Floating Point Numbers. CMPE12cCyrus Bazeghi 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64.
Lecture 3 Number Representation 2 This week – Recap Addition – Addition circuitry – Subtraction of integers in binary – Representing numbers with fractional.
Number Systems Standard positional representation of numbers:

Floating Point Numbers
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
Binary numbers and arithmetic. ADDITION Addition (decimal)
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
The Binary Number System
Simple Data Type Representation and conversion of numbers
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
Computer Arithmetic Nizamettin AYDIN
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Information Representation: Negative and Floating Point.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computing Systems Basic arithmetic for computers.
Computer Architecture
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
9.4 FLOATING-POINT REPRESENTATION
Floating Point Representations CDA 3101 Discussion Session 02.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Integer & Floating Point Representations CDA 3101 Discussion Session 05.
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Floating Point Arithmetic
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Integer and Fixed Point P & H: Chapter 3
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Binary Arithmetic.
Floating Point Numbers
CS 160 Lecture 4 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Number Representation and Arithmetic Circuits
Numbers in Computers.
Number Systems and Computer Arithmetic Winter 2014 COMP 1380 Discrete Structures I Computing Science Thompson Rivers University.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Introduction To Computer Science
Numbers in a Computer Unsigned integers Signed magnitude
What to bring: iCard, pens/pencils (They provide the scratch paper)
Cosc 2P12 Week 2.
Cosc 2P12 Week 2.
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1

DCO 2 Bit Operations AND & OR | ONE'S COMPLEMENT ~ EXCLUSIVE OR ^ SHIFT (right) >> SHIFT (left) <<

DCO 3 Operation - examples AND 1 & 1 = 1; 1& 0 = 0 OR 1 |1 = 1; 1| 0 = 1; 0|0 = 0 ~ 0 =~1; 1 =~0; ^ 0^ 0 = 0; 1^1 = 0; 1^0 =1; 0^1 = 1 >> 0x010 = 0x001 <<1 >1

DCO 4 AND Example (0xf2) (0xfe) (and) & (0xf2) char c = 0xf2; char d = 0xfe; Char e = c & d; //e is 0xf2

DCO 5 OR Example (0xf2) (0xfe) (or) | (0xfe) char c = 0xf2; char d = 0xfe; char e = c | d; //e is 0xfe

DCO 6 One’s complement (0xf2) ~ (0x0d) char c = 0xf2; char e = ~c; //e is 0x0d

DCO 7 EXCLUSIVE OR (0xf2) (0xfe) (^) (0x0c) char c = 0xf2; char d = 0xfe; char e = c ^ d; //e is 0x0c

DCO 8 SHIFT >> 1 - (right) by one bit (0xf2) >> 1 (shift right by one bit) (0x79) char c = 0xf2; char e = c >>1; //e is 0x79

DCO 9 SHIFT >> 2 - by two bits (0xf2) >> 2 (shift right by one bit) (0x3c) char c = 0xf2; char e = c >>2; //e is 0x3c

DCO 10 SHIFT << 1 - (left) by one bit (0xf2) << 1 (shift right by one bit) (0xe4) char c = 0xf2; char e = c <<1; //e is 0xe4

DCO 11 SHIFT << 2 - by two bits (0xf2) >> 2 (shift right by one bit) (0xc8) char c = 0xf2; char e = c <<2; //e is 0xc8

DCO 12 Results or bit operation (example) ( 1 | 2) == 3 (1 | 3) == 3 (1 & 2) == 0 (1 & 3) == 1 (2 & 3) == 2 (0 ^ 3) == 3 (1 ^ 3) == 2 (2 ^ 3) == 1 (3 ^ 3) == 0 ~0 == -1 (signed) or 255 (unsigned). ~23 == -24 (signed) or 232 (unsigned).

DCO 13 Integer Formats, Signs, and Precision Overflow

DCO 14 Data representation 150 (decimal) is 128(2^7) + 16(2^4) + 4(2^2) + 2(2^1). We can rewrite this as: 1* *64 + 0*32 + 1*16 + 0*8 + 1*4 + 1*2 + 0*1 or (in hex), In 8 bits, for 32 bits, 2^32

DCO 15 Format In C, the size of integer types (short, int, long, etc.) is implementation dependent, but on most machines: chars are 8 bits ints and longs are 32 bits shorts are 16 bits

DCO 16 One’s complement & two’s complement //original data //reverse 1 to 0, 0 to 1 One’s complement (add one to one’s complement) Two’s complement

DCO 17 Application of twos’ complement – can be converted into two’s complement The operation becomes addition instead of subtraction Two’s complement – is – is = Convert “-” to “+”

DCO 18 Signed integer of 100 Negative sign is represented by 1 (most significant bit) 100 (decimal) 0x0064 (hex) positive -100 (decimal) 0xff9c (hex) negative

DCO 19 Example of – 101 (decimal) 101 (decimal ) is 0x0065 (hex) ( 32 bits integer) -101 is two’s complement 0xff9b Convert 0 to 1, 1 to 0 and then add (101 in decimal) (convert 1 to 0 and 0 to 1) (add 1, result)

DCO 20 Left & right Shift 101 (dec) is 0x0065 (hex) Shift right by one bit >> (101 dec) >> 1 (shift left) (50 dec), not 50.5

DCO 21 Overflow When integers are too big to fit into a word, overflow occurs. 16-bit unsigned integer, the largest is If you add (dec), it produces (binary) (overflow)

DCO 22 Floating Fixed-Point Representations – Floating-Point Representations such as 32.45, x 10, x 100 Normalization and Hidden Bits IEEE Floating Point Details

DCO 23 Fixed-Point Representations Such as The decimal point is fixed

DCO 24 Floating point A floating-point number is really two numbers packed into one string of bits. One of the numbers is simply a fixed-point binary number, which is called the mantissa. The other number acts to shift the binary point left or right to keep the mantissa in a useful range. This number is called the exponent.

DCO 25 Example of Floating E x 10^4

DCO 26 Expression 1 bit sign bit, 8 bit exponent, and 23 bit Mantissa (total 32 bits) -1^Sign * 2^(Exponent - 127) * (1 + Mantissa * 2^-23) Zero, sign bit is 0, Negative, sign bit is 1 Exponent is unsigned, minus 127. That is if the value is 128, it means 128 – 127 = 1, if the value is 256, it means 256 – 127 = 128, or the value is zero, it means 0 – 127 = -127.

DCO 27 Example

DCO 28 Expression - Mantissa Mantissa is unsigned bit, the expression is 1 + Mantissa * 2^( -23) If Mantissa is zero, the expression becomes * 2^(-23) = 1 If Mantissa is 2^23, the expression becomes 1 + 2^23 * 2 ^(-23) = = 2 It ranges from 1 to 2

DCO 29 Example 2.5 (floating point) Sign: positive (1) Exponent : : 128 (128 – 127 = 1) Mantissa: , 1.25 Result 1 x 1.25 x 2^1 = 2.5

DCO 30 Example Determine the values of Sign = 1, negative Exponent = 122 so exponent = -5 (122 – 127) Mantissa: = 1.1 So result – 1 x 1.1 x 2^(-5) 2 = (decimal)

DCO 31 Two representation of Zero When the sign bit is zero, positive, exponent is zero and Mantissa is zero When the sign bit is 1, negative, exponent is zero and Mantissa is zero In short, there are two formats of ZERO

DCO 32 IEEE Double Precision – 64 bits 64 bits with 11 exponent bits 52 mantissa bits Plus one bit sign bit C++ uses 32 bits (4 bytes) instead of 64 bits

DCO 33 Summary Bit operation, &, |, ~, >> or << Representation of data, int, short, long Floating point – sign, magnitude, mantissa for example, -3.4 x10^4 - (negative), 3.5 (mantissa), 4 magnitude 0x can be an integer, floating point, or a statement. That is why we need to define int i; Char a;