ECE 103 Engineering Programming Chapter 3 Numbers

Slides:



Advertisements
Similar presentations
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Advertisements

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.
Chapter 5 Floating Point Numbers. Real Numbers l Floating point representation is used whenever the number to be represented is outside the range of integer.
Number Systems Standard positional representation of numbers:
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Binary Number Systems.
Number Systems.
The Binary Number System
Simple Data Type Representation and conversion of numbers
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Data Representation and Computer Arithmetic
Chapter 3 Section 1 Number Representation Modern cryptographic methods, unlike the classical methods we just learned, are computer based. Representation.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
ITEC 1011 Introduction to Information Technologies 4. Floating Point Numbers Chapt. 5.
Integer & Floating Point Representations CDA 3101 Discussion Session 05.
Chapter 1  Number Systems Decimal System Binary System Octal System Hexadecimal System  Binary weighted cods Signed number binary order  1’s and 2’s.
CSPP58001 Floating Point Numbers. CSPP58001 Floating vs. fixed point Floating point refers to a binary decimal representation where there is not a fixed.
Number Systems & Operations
Floating Point in Binary 1.Place Value Chart:
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
Number Representation and Arithmetic Circuits
ECE 103 Engineering Programming Chapter 3 Numbers Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Lecture 6: Floating Point Number Representation Information Representation: Floating Point Number Representation Lecture # 7.
1 Digital Logic Design (41-135) Chapter 5 Number Representation & Arithmetic Circuits Younglok Kim Dept. of Electrical Engineering Sogang University Spring.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 9 Computer Arithmetic
FLOATING-POINT NUMBER REPRESENTATION
William Stallings Computer Organization and Architecture 8th Edition
MATH Lesson 2 Binary arithmetic.
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Programming and Data Structure
Octal to Decimal Decimal Octal Binary Hexadecimal.
Number Representation
Introduction To Computer Science
Floating Point Representations
Number Systems and Binary Arithmetic
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
CSE 102 Introduction to Computer Engineering
William Stallings Computer Organization and Architecture 7th Edition
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Chapter 2 Bits, Data Types & Operations Integer Representation
CSCI206 - Computer Organization & Programming
Number Representations
ECEG-3202 Computer Architecture and Organization
Cosc 2P12 Week 2.
Number Representation
Chapter 8 Computer Arithmetic
Storing Integers and Fractions
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Cosc 2P12 Week 2.
Number Representations
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

ECE 103 Engineering Programming Chapter 3 Numbers Herbert G. Mayer, PSU Status 6/20/2016 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

Syllabus Binary Numbers Bitwise Operations Other Base Representations Positive and Negative Integers Floating Point

Binary Numbers Bit  Smallest unit of information (binary digit) A single bit has two distinct states: 0 (logical False) 1 (logical True) A binary number consists of n bits grouped together. LSB MSB bn-1bn-2…b1b0 = bn-12n-1 + bn-22n-2 + … + b121 + b020 2

Table 1: Given n bits, the number of possible states = 2n - 10 1024 20 1048576 1 2 11 2048 21 2097152 4 12 4096 22 4194304 3 8 13 8192 23 8388608 16 14 16384 24 16777216 5 32 15 32768 : 6 64 65536 30 1073741824 7 128 17 131072 31 2147483648 256 18 262144 4294967296 9 512 19 524288 18446744073709551616 3

Convert from binary to its equivalent base 10 value  Expand the powers of two. Example: What is 11102 in decimal? 11102 = (123) + (122) + (121) + (020) = (18) + (14) + (12) + (01) = 1410 Convert from base 10 to its equivalent binary value  Successively divide by two; keep track of remainders. Example: What is 1410 in binary? Base 10 Remainder 14 / 2 = 7 7 / 2 = 3 1 3 / 2 = 1 1 / 2 = 0 Read the remainders backwards. Hence, 1410 = 11102 4

Bitwise Operations 1 1 1 1 1 A B A & B A B A | B A B A ^ B A ~A 1 A B A | B 1 A B A ^ B 1 A ~A 1 Bitwise Complement Bitwise AND Bitwise OR Bitwise XOR A B A + B Carry 1 Bitwise Addition 5

Logic operations are done a bit at a time (unary operator) or a pair of bits at a time (binary operator). Example: ~1011 = 0100 Complement 1010 & 1100 = 1000 Bitwise AND 1010 | 1100 = 1110 Bitwise OR 1010 ^ 1100 = 0110 Bitwise XOR ■ ■ ■ ■ 6

Table 2: 4-bit positive integer conversion table Other Base Representations Octal (base 8  0, …, 7) Hexadecimal (base 16  0, …, 9, A, B, C, D, E, F) Table 2: 4-bit positive integer conversion table Dec Bin Oct Hex 0000 8 1000 10 1 0001 9 1001 11 2 0010 1010 12 A 3 0011 1011 13 B 4 0100 1100 14 C 5 0101 1101 15 D 6 0110 1110 16 E 7 0111 1111 17 F 7

Converting from binary to its equivalent hex: 1) Separate binary value into 4-bit groups 2) Replace each group by its hex value Example: 4410010 = 10101100010001002 = AC4416 Converting from hex to its equivalent binary: Replace each hex value by its 4-bit binary value. 2741110 = 6B1316 = 01101011000100112 8

Positive and Negative Integer Numbers Integers are exactly representable in base 2 Table 3: 4-bit positive only values 0 to 15 If only positive integers and zero are needed, then all of the bits in the binary representation are available to express the value. Given : n bits Range: 0 to 2n – 1 Base 10 Base 2 0000 8 1000 1 0001 9 1001 2 0010 10 1010 3 0011 11 1011 4 0100 12 1100 5 0101 13 1101 6 0110 14 1110 7 0111 15 1111 9

Table 4: 4-bit positive and negative values -8 to +7 For negative integers, the most significant bit (MSB) of the binary value is reserved as a sign bit. Negative values are expressed as 2’s complement. Table 4: 4-bit positive and negative values -8 to +7 If both positive and negative integers are needed, the maximum positive value is reduced by a factor of two. Given : n bits Range: –2n-1 to 2n-1 – 1 Base 10 Base 2 (2's comp) 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 10

Floating Point Numbers Floating point is used to express real-valued numbers. There is an implicit decimal point. Example: 2.0 3.1415 –634.9 Example: In scientific notation format (base 10) –6.349 × 102 mantissa sign base exponent 11

IEEE 754 single-precision (32-bit) standard s e1e2…e8 b1b2…b23 Binary can be used to represent floating point values, but usually only as an approximation. IEEE 754 single-precision (32-bit) standard s e1e2…e8 b1b2…b23 1 bit Sign 0→ + 1→ – 8 bits Interpreted as unsigned integer e' 23 bits Interpreted as a base 2 value defined as m' = 0.b1b2…b23 = b12-1 + b22-2 +…+ b232-23 if e' ≠ 0 then FP number = (-1)s × (1 + m') × 2e'-127 if e' = 0 then FP number = (-1)s × m' × 2-126 12

Example: IEEE 754 single precision (32-bit) 01010110010010100000000000000000 The more bits available, the more precise the mantissa and the larger the exponent range. See: https://en.wikipedia.org/wiki/IEEE_floating_point s = 0 e' = 17210 m' = 2-1 + 2-4 + 2-6 = 0.578125 Number = (-1)s × (1 + m') × 2e'-127 = 1.578125 × 245 ≈ 5.55253372027 × 1013 13