ECEN 301Discussion #19 – Binary Numbers1 Numbered Moses 1:33,35,37 33 And worlds without number have I created; and I also created them for mine own purpose;

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

ECEN 301Discussion #21 – Boolean Algebra1 DateDayClass No. TitleChaptersHW Due date Lab Due date Exam 12 NovWed21Boolean Algebra13.2 – 13 EXAM 2 13 NovThu.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Introduction to Programming with Java, for Beginners
Storage of Bits Computers represent information as patterns of bits
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Chapter 2 Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2-2 How do we.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Binary Representation and Computer Arithmetic
Introduction to Computing Systems from bits & gates to C & beyond Chapter 2 Bits, Data Types & Operations Integer Representation Floating-point Representation.
Dr. Bernard Chen Ph.D. University of Central Arkansas
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Arithmetic Nizamettin AYDIN
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
IT253: Computer Organization
Chapter 2 - Data Types. BYU CS/ECEn 124Chapter 2 - Data Types2 Today… Unit 1 slides and homework in JFSB B115 Problems with CCE on Talmage Window’s machines…
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Idea 1: Bits Two states in a digital machine: 1.presence of.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Logic Design Dr. Yosry A. Azzam. Binary systems Chapter 1.
PART 2 Data Types 1. Integers 2. 2’s Complement 3. Conversion
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
Bits, Data Types, and Operations Slides based on set prepared by Gregory T. Byrd, North Carolina State University.
The Teacher CP4 Binary and all that… CP4 Revision.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Chapter 2 Bits, Data Types, and Operations. 2-2 How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
CHAPTER 1 INTRODUCTION TO DIGITAL LOGIC
AEEE2031 Data Representation and Numbering Systems.
Number Systems & Operations
Instructor:Po-Yu Kuo 教師:郭柏佑
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
NUMBER SYSTEMS.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
CS2100 Computer Organisation
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
Programming and Data Structure
Number Representation
Integer Real Numbers Character Boolean Memory Address CPU Data Types
CHAPTER 1 INTRODUCTION TO DIGITAL LOGIC
CHAPTER 1 : INTRODUCTION
Chapter 3 Data Representation
CS1010 Programming Methodology
Presentation transcript:

ECEN 301Discussion #19 – Binary Numbers1 Numbered Moses 1:33,35,37 33 And worlds without number have I created; and I also created them for mine own purpose; and by the Son I created them, which is mine Only Begotten. 37 And the Lord God spake unto Moses, saying: The heavens, they are many, and they cannot be numbered unto man; but they are numbered unto me, for they are mine 35 …all things are numbered unto me, for they are mine and I know them. 3 Nephi 18:31 31 …behold I know my sheep, and they are numbered.

ECEN 301Discussion #19 – Binary Numbers2 Lecture 19 – Binary Numbers

ECEN 301Discussion #19 – Binary Numbers3 Digital vs. Analog Wristwatches (numbers vs. hands) LP’s vs. CD’s Rotary phone vs. Cell phone NTSC vs. HDTV Slide rule vs. calculator 737’s vs. 777’s

ECEN 301Discussion #19 – Binary Numbers4 Digital vs. Analog AnalogDigital

ECEN 301Discussion #19 – Binary Numbers5 Digital vs. Analog Digital signals are limited to a set of possible values (precision), i.e. limited to discrete values Set of 10 different symbol values → decimal Set of 2 different symbol values → binary

ECEN 301Discussion #19 – Binary Numbers6 Number Representations Decimal means that we have ten digits to use in our representation (the symbols 0 through 9) Example: What is 3,546? three thousands + five hundreds + four tens + six ones. 3, = 3     10 0 How about negative numbers? We use two more symbols to distinguish positive and negative, namely, + and -.

ECEN 301Discussion #19 – Binary Numbers7 Example 1: What is ? Number Representations

ECEN 301Discussion #19 – Binary Numbers8 Example 1: What is ? Depends on what radix or base we use Decimal base = 10 (digit set: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) Binary base = 2 (digit set: {0, 1}) Hexadecimal base = 16 (digit set: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}) Other? base = r (digit set: {0, … r-1}) Number Representations

ECEN 301Discussion #19 – Binary Numbers9 2 - binary 3 - ternary 4 - quaternary 5 - quinary 6 - senary 7 - septenary 8 - octal 9 - nonary 10 - denary, although this is never used; instead decimal is the common term undenary 12 - duodenary, although this is never used; duodecimal is the accepted word senidenary, although this is never used; see the discussion in hexadecimal vegesimal 60 - sexagesimal Etymologically Correct Base Names

ECEN 301Discussion #19 – Binary Numbers10 Example 1: What is ? Depends on what radix or base we use Decimal base = 10 (digit set: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) Binary base = 2 (digit set: {0, 1}) Hexadecimal base = 16 (digit set: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}) Other? base = r (digit set: {0, … r-1}) For base = 1        For base = 1        2 -3 For base r r = 1  r  r  r  r  r  r  r -3 Number Representations

ECEN 301Discussion #19 – Binary Numbers11 Binary Numbers Binary means that we have two digits to use in our representation: the symbols 0 and 1 Example: What is ? one eights + zero fours + one twos + one ones = 1     2 0

ECEN 301Discussion #19 – Binary Numbers12 Binary Numbers Bits rely only on approximate physical values. A logical ‘ 1 ’ is a relatively high voltage (1.2V, 3.3V, 5V). A logical ‘ 0 ’ is a relatively low voltage (0V - 1V). Bit: a single binary symbol (i.e. a 0 or a 1) Byte: a sequence of 8 bits

ECEN 301Discussion #19 – Binary Numbers13 Binary Numbers Numbers are represented by a sequence of bits: A collection of two bits has four possible values or states: 00, 01, 10, 11 A collection of three bits has eight possible states: 000, 001, 010, 011, 100, 101, 110, 111 A collection of n bits has 2 n possible states. By using groups of bits, we can achieve high precision. 8 bits ===> number of states: bits ===> number of states: 65, bits ===> number of states: 4,294,967, bits ===> number of states: 18,446,744,073,709,550,000

ECEN 301Discussion #19 – Binary Numbers14 Data Types Bits alone don’t give information – they must be interpreted Data types are what interpret bits Example: interpret the following bits The integers: and ? The characters: H E X A ? The floating-point number: ? Other?

ECEN 301Discussion #19 – Binary Numbers15 Data Types Unsigned integers 0, 1, 2, 3, 4, …(non-negative integers) Signed integers …, -3, -2, -1, 0, 1, 2, 3, … (integer + sign) Floating point numbers PI = x 10 0 (mantissa + exponent) Characters (ascii) ‘0’, ‘1’, ‘2’, …, ‘a’, ‘b’, ‘c’, …, ‘A’, ‘B’, ‘C’, …, ‘#’, …

ECEN 301Discussion #19 – Binary Numbers16 Unsigned Integers x x10 + 9x1 = 3291x4 + 0x2 + 1x1 = 5 Most Significant Bit ( MSB ) Least Significant Bit ( LSB ) Weighted positional notation “3” is worth 300, because of its position, while “9” is only worth 9 What do these unsigned binary numbers represent?

ECEN 301Discussion #19 – Binary Numbers17 Unsigned Integers Example 2: What numbers can be represented with 3 bits?

ECEN 301Discussion #19 – Binary Numbers18 Unsigned Integers Example 2: What numbers can be represented with 3 bits? decimal

ECEN 301Discussion #19 – Binary Numbers19 Binary Arithmetic Base-2 addition – just like base-10! add from right to left, propagating carry carry Subtraction, multiplication, division,… 01111

ECEN 301Discussion #19 – Binary Numbers20 Signed Binary Integers n bits → 2 n distinct values ½ for negative values ½ for positive values BUT – need a symbol for zero Determine the range of values for n bits

ECEN 301Discussion #19 – Binary Numbers21 Signed Binary Integers 3 common representations for signed integers: 1.Sign magnitude 2.1’s compliment 3.2’s compliment Most common for computers

ECEN 301Discussion #19 – Binary Numbers22 Sign-Magnitude Range: Representations binary => 15 decimal 11111=> => => -0 Problem Difficult addition/subtraction check signs convert to positive use adder or subtractor as required How to add two sign-magnitude numbers? Ex: 1 + (-4) The MSB encodes the sign: 0 = + 1 = 

ECEN 301Discussion #19 – Binary Numbers23 1’s Complement Range: Representations binary => 6 decimal 11001=> => => -0 Problem Difficult addition/subtraction no need to check signs as before cumbersome logic circuits end-around-carry How to add to one’s complement numbers? Ex: 4 + (-3) To negate a number, Invert it, bit-by-bit. MSB still encodes the sign: 0 = + 1 = 

ECEN 301Discussion #19 – Binary Numbers24 Two’s Complement Problems with sign-magnitude and 1’s complement two representations of zero (+0 and –0) arithmetic circuits are complex Two’s complement representation developed to make circuits easy for arithmetic. only one representation for zero just ADD the two numbers to get the right answer (regardless of sign)

ECEN 301Discussion #19 – Binary Numbers25 Two’s Complement Range: Representation: If number is positive or zero, normal binary representation, zeroes in upper bit(s) If number is negative, start with positive number flip every bit (i.e., take the one’s complement) then add one (5) (9) (1’s comp)(1’s comp) (-5)(-9) MSB still encodes the sign: 0 = + 1 = 

ECEN 301Discussion #19 – Binary Numbers26 Two’s Complement Example 3: What is in decimal? What is it’s 2’s complement?

ECEN 301Discussion #19 – Binary Numbers27 Two’s Complement Example 3: What is in decimal? What is it’s 2’s complement? = 0        2 0 = 53 10

ECEN 301Discussion #19 – Binary Numbers28 Two’s Complement Example 3: What is in decimal? What is it’s 2’s complement? = 0        2 0 = (53) (1’s comp) (-53)

ECEn/CS 124Discussion #2 – Chapter 229 2’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2

ECEn/CS 124Discussion #2 – Chapter 230 2’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2 –MSB

ECEn/CS 124Discussion #2 – Chapter 231 2’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2 –MSB + remaining bits

ECEn/CS 124Discussion #2 – Chapter 232 2’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2 –MSB + remaining bits

ECEn/CS 124Discussion #2 – Chapter 233 2’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2 –MSB + remaining bits

ECEn/CS 124Discussion #2 – Chapter 234 2’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2 –MSB + remaining bits = = –1

ECEN 301Discussion #19 – Binary Numbers35 Two’s Complement Positional number representation with a twist MSB has a negative weight 0110 = = = = -2 –MSB + remaining bits = – = = -1

ECEN 301Discussion #19 – Binary Numbers36 Two’s Complement Shortcut To take the two’s complement of a number: 1.copy bits from right to left until (and including) the first 1 2.flip remaining bits to the left (1’s comp) (copy)(flip)

ECEN 301Discussion #19 – Binary Numbers37 Two’s Complement Negation To negate a number, invert all the bits and add 1 (or use shortcut) (??)

ECEN 301Discussion #19 – Binary Numbers38 Decimal to Binary Conversion Positive numbers start with empty result if decimal number is odd, prepend ‘ 1 ’ to result else prepend ‘ 0 ’ divide number by 2, throw away fractional part (INTEGER divide) if number is non-zero, go back to  else you are done Negative numbers do above for positive version of number and negate result.

ECEN 301Discussion #19 – Binary Numbers39 Decimal to Binary Conversion

ECEN 301Discussion #21 – Boolean Algebra40 Hexadecimal Notation Binary is hard to read and write by hand Hexadecimal is a common alternative 16 digits are ABCDEF = 0x478F = 0xDEAD = 0xBEEF = 0xA5A5 Binary Hex Dec A B C D E F15 0x is a common prefix for writing numbers which means hexadecimal 1.Separate binary code into groups of 4 bits (starting from the right) 2.Translate each group into a single hex digit

ECEN 301Discussion #19 – Binary Numbers41 Binary to Hex Conversion Every four bits is a hex digit. start grouping from right-hand side D4F8A3 This is not a new machine representation, just a convenient way to write the number.

ECEN 301Discussion #19 – Binary Numbers42 Binary to Hex Conversion Properly sign-extending is important if the binary number is signed

ECEN 301Discussion #19 – Binary Numbers43 Binary to Hex Conversion Properly sign-extending is important if the binary number is signed CE/2