Number Systems Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100,

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

The Binary Numbering Systems
CHAPTER 2 Number Systems, Operations, and Codes
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Data Representation Computer Organization &
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
Data Representation COE 205
Binary Representation
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
EE 261 – Introduction to Logic Circuits
Data Representation Number Systems.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
BR 8/99 Digital Devices Integrated Circuits that operate on Digital Data are in 95% of every electrical powered device in the U.S. The theory of operation.
Programmable Logic Controllers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Numbering systems.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
Computers Organization & Assembly Language
Digital Systems and Logic Design
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
ECE 3110: Introduction to Digital Systems Review #1 (Chapter 1,2)
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
IT253: Computer Organization
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Logic Design Dr. Yosry A. Azzam. Binary systems Chapter 1.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
ECE 3110: Introduction to Digital Systems Number Systems.
Number systems & Binary codes MODULE 1 Digital Logic Design Ch1-2 Outline of Chapter 1  1.1 Digital Systems  1.2 Binary Numbers  1.3 Number-base Conversions.
Number Systems and Codes. CS2100 Number Systems and Codes 2 NUMBER SYSTEMS & CODES Information Representations Number Systems Base Conversion Negative.
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Positional Number Systems Decimal, Binary, Octal and Hexadecimal Numbers Wakerly Section
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Digital Design Basics Analog vs Digital Why we need digital? Reproducibility, economy, programmability… Digital Devices Gates, FFs Combinational, sequential.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
MECH1500 Chapter 3.
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Logic Design: Part 1.
Chapter 1: Binary Systems
ECE 3110: Introduction to Digital Systems Number Systems.
ECE 2110: Introduction to Digital Systems
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
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.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Positional Number Systems Decimal, Binary, Octal and Hexadecimal Numbers Wakerly Section
NUMBER SYSTEMS.
Lec 3: Data Representation
Digital Devices Integrated Circuits that operate on Digital Data are in 95% of every electrical powered device in the U.S. The theory of operation of these.
Wakerly Section 2.4 and further
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
CHAPTER 69 NUMBER SYSTEMS AND CODES
Presentation transcript:

Number Systems Number Systems Stone Age: knots, some stone marks Roman Empire: more systematic notation I, II, III, IV, V, VI, VII.VIII, IX, X, C=100, D=500, M=1000, L=50 Concept of zero by –Maya- I century, Hindu-V century Positional-value systems: decimal, binary, octal, etc..

Positional-Value System The value of a digit (“digit” from Latin word for finger) depends on its position MSD Decimal LSD point Positional values (weights) We will write ( ) 10

Binary: Base-2 Number System We write: ( ) 2 base point or radix Digits are called bits

Binary Representation The basis of all digital data is binary representation. Binary - means ‘two’ –1, 0 –True, False –Hot, Cold –On, Off We must be able to handle more than just values for real world problems –1, 0, 56 –True, False, Maybe –Hot, Cold, LukeWarm, Cool –On, Off, Leaky

Number Systems To talk about binary data, we must first talk about number systems The decimal number system (base 10) you should be familiar with! –A digit in base 10 ranges from 0 to 9. –A digit in base 2 ranges from 0 to 1 (binary number system). A digit in base 2 is also called a ‘bit’. –A digit in base R can range from 0 to R-1 –A digit in Base 16 can range from 0 to 16-1 (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to represent values 10 to 15. Base 16 is also called Hexadecimal or just ‘Hex’.

Positional Number Systems The traditional number system is called a positional number system. A number is represented as a string of digits. Each digit position has a weight assoc. with it. Number’s value = a weighted sum of the digits

Positional Notation – more examples Value of number is determined by multiplying each digit by a weight and then summing. The weight of each digit is a POWER of the BASE and is determined by position = 9 x x x x x = = % = 1x x x x x x2 -2 = = $ A2F = 10x x x16 0 = 10 x x x 1 = = 2607 decimal binary hex

Base 10, Base 2, Base 16 The textbook uses subscripts to represent different bases (ie. A2F 16, , ) We will use special symbols to represent the different bases. The default base will be decimal, no special symbol for base 10. The ‘$’ will be used for base 16 ( $A2F) The ‘%’ will be used for base 2 (% ) If ALL numbers on a page are the same base (ie, all in base 16 or base 2 or whatever) then no symbols will be used and a statement will be present that will state the base (ie, all numbers on this page are in base 16).

Common Powers 2 -3 = = = = = = = = = = = = = = = = = 1 = = 16 = = 256 = = 4096 = = 1024 = 1 K 2 20 = = 1 M (1 Megabits) = 1024 K = 2 10 x = = 1 G (1 Gigabits)

Octal and Hexadecimal (“Hex”) Numbers Octal = base 8 Hexadecimal = base 16 –Use A – F to represent the values 10 through 16 in each position.

Usefulness of Octal and Hex Numbers Useful for representing multi-bit binary numbers because their radices are integer multiples of = 2 5 A F. B E 16 DecimalBinaryOctalHex A B C D E F

Comparison of binary, decimal, octal and hexadecimal numbers examples of octal and hex numbers

Decimal to Hex Conversions Convert 53 to Hex 53/16 = 3, rem = 5 3 /16 = 0, rem = 3 53 = $ 35 = 3 x x 16 0 = = 53

Hex (base 16) to Binary Conversion Each Hex digit represents 4 bits. To convert a Hex number to Binary, simply convert each Hex digit to its four bit value. Hex Digits to binary: $ 0 = % 0000 $ 1 = % 0001 $2 = % 0010 $3 = % 0011 $4 = % 0100 $5 = % 0101 $6 = % 0110 $7 = % 0111 $8 = % 1000 Hex Digits to binary (cont): $ 9 = % 1001 $ A = % 1010 $ B = % 1011 $ C = % 1100 $ D = % 1101 $ E = % 1110 $ F = % 1111

Conversions: Hex to Binary, Binary to Hex $ A2F = % $ 345 = % Binary to Hex is just the opposite, create groups of 4 bits starting with least significant bits. If last group does not have 4 bits, then pad with zeros for unsigned numbers. % = % = $ 51 Padded with a zero Binary to hex conversion Hex to Binary conversion

A Trick! If faced with a large binary number that has to be converted to decimal, we first convert the binary number to HEX, then convert the HEX to decimal. Less work! % = % = $ D F 3 = 13 x x x16 0 = 13 x x x 1 = = 3571 Of course, you can also use the binary, hex conversion feature on your calculator. You can use calculators on exam

Bah! I thought we were talking about Binary DATA!!! Yah, we were! How many binary DIGITS does it take to represent our data??

Binary Codes One Binary Digit (one bit) can take on values 0, 1. We can represent TWO values: (0 = hot, 1 = cold), (1 = True, 0 = False), (1 = on, 0 = off). Two Binary digits (two bits) can take on values of 00, 01, 10, 11. We can represent FOUR values: (00 = hot, 01 = warm, 10 = cool, 11 = cold). Three Binary digits (three bits) can take on values of 000, 001, 010, 011, 100, 101, 110, 111. We can represent 8 values 000 = Black, 001 = Red, 010 = Pink, 011 = Yellow, 100 = Brown, 101 = Blue, 110 = Green, 111 = White.

Binary Codes (cont.) N bits (or N binary Digits) can represent 2 N different values. (for example, 4 bits can represent 2 4 or 16 different values) N bits can take on unsigned decimal values from 0 to 2 N -1. Codes usually given in tabular form black red pink yellow brown blue green white

Code Conversions

( ) 2 ( ) 4 ( ) 8 ( ) 16 To convert a binary number to a system which is base-2 z, group digits together by z and convert each group separately > ( ) A Converting from binary base hex as an example of base 2 Z

Conversion of Any Base to Decimal Converting from ANY base to decimal is done by multiplying each digit by its weight and summing. % = 1x x x x x x2 -2 = = Binary to Decimal Hex to Decimal $ A2F = 10x x x16 0 = 10 x x x 1 = = 2607

Conversion ( ) I ( ) 10 express number as a power series in I, and add all terms using decimal addition Converting from base I to decimal

Decimal-to-Radix-r Conversions Radix-r-to-decimal conversions are easy since we do arithmetic in decimal. However, decimal-to-radix-r conversions using decimal arithmetic is harder. To do the latter conversion, we convert the integer and fractional parts separately and add the results afterwards.

Convert ( ) 10 ( ) r Integer part: –Divide the number and all successive quotients by r –accumulate the remainders Fractional part: –Multiply the number and successive fractions by r –accumulate the integers

Conversion of Decimal Integer To ANY Base Divide Number N by base R until quotient is 0. Remainder at EACH step is a digit in base R, from Least Significant digit to Most significant digit. Convert 53 to binary 53/2 = 26, rem = 1 26/2 = 13, rem = 0 13/2 = 6, rem = 1 6 /2 = 3, rem = 0 3/2 = 1, rem = 1 1/2 = 0, rem = 1 53 = % = 1x x x x x x2 0 = = 53 Least Significant Digit Most Significant Digit

Decimal-to-Radix-r Conversions: Integer Part Successively divide number by r, taking remainder as result. Example: Convert to binary. 57 / 2 = 28 remainder 1 (LSB) /2 = 14 remainder 0 /2 = 7 remainder 0 /2 = 3 remainder 1 /2 = 1 remainder 1 /2 = 0 remainder 1 (MSB) Answer:

Decimal-to-Radix-r Conversions: Fractional Part Successively multiply number by r, taking integer part as result and chopping off integer part before next iteration. May be unending! Example: convert.3 10 to binary..3 * 2 =.6 integer part = 0.6 * 2 = 1.2 integer part = 1.2 * 2 =.4 integer part = 0.4 * 2 =.8 integer part = 0.8 * 2 = 1.6 integer part = 1.6 * 2 = 1.2 integer part = 1, etc. Answer =

More Conversion methods for common radices

Least Significant Digit Most Significant Digit 53 = % Most Significant Digit (has weight of 2 5 or 32). For base 2, also called Most Significant Bit (MSB). Always LEFTMOST digit. Least Significant Digit (has weight of 2 0 or 1). For base 2, also called Least Significant Bit (LSB). Always RIGHTMOST digit.

Binary Data in your life The computer screen on your Win 98 PC can be configured for different resolutions. One resolution is 600 x 800 x 8, which means that you have 600 dots vertically x 800 dots horizontally, with each dot using 8 bits to take on 256 different colors. (actually, a dot is called a pixel). Need 8 bits to represent 256 colors ( 2 8 = 256). Total number of bits needed to represent the screen is then: 600 x 800 x 8 = 3,840,000 bits (or just under 4 Mbits) Your video card must have at least this much memory on it. 1 Mbits = 1024 x 1024 = 2 10 x 2 10 = Kbits = 1024 = 2 10.

Addition and Subtraction Use same technique as decimal Except that the addition and subtraction tables are different Already seen addition table –Truth table for Sum and Cout function

Examples of decimal and corresponding binary additions

Examples of decimal and corresponding binary subtractions

Binary Addition and Subtraction Table

Subtraction table b in xyb out d borrow in borrow out Discuss this method in comparison with previous method from the class to create a subtractor

Addition and Subtraction of Octal and Hexadecimal Numbers Not really too different But the addition and subtraction tables must be developed.

The concept of 10’s complement

digit complements in binary, octal, decimal and hexadecimal

Representation of Negative Numbers More accurately: representation of signed numbers –Signed-magnitude representation –Radix-complement representation 2’s-complement representation –Diminished radix-complement representation –Ones’ complement representation –Excess representations

Comparison of decimal and 4-bit numbers. Complements Decimal numbers, their two’s complements, ones’ complements, signed magniture and excess 2 m-1 binary codes Existence of two zeros! EXPLAIN

Signed-magnitude representation Also called, “sign-and-magnitude representation” A number consists of a magnitude and a symbol representing the sign Usually 0 means positive, 1 negative –Sign bit –Usually the entire number is represented with 1 sign bit to the left, followed by a number of magnitude bits

Machine arithmetic with signed- magnitude representation Takes several steps to add a pair of numbers –Examine signs of the addends –If same, add magnitudes and give the result the same sign as the operands –If different, must… Compare magnitude of the two operands Subtract smaller number from larger Give the result the sign of the larger operand For this reason the signed-magnitude representation is not as popular as one might think because of its “naturalness”

Complement number systems Negates a number by taking its complement instead of negating the sign Exact meaning of taking its complement is defined in various ways – will see Not natural for humans, but better for machine arithmetic Will describe 2 complement number systems –Radix complement – very popular in real computers –Diminished radix-complement – not very useful, may skip or not spend much time on it

Radix-complement number representation Must first decide how many bits to represent the number – say n. Complement of a number = r n – number Example: 4-bit decimal: –Original number = 3524 –10’s complement = = and positive numbers: Negative numbers: , where 9999 is ‘minus 1.’

Two’s-complement representation Just radix-complement when radix = 2 Used a lot in computers and other digital arithmetic circuits 0 and positive numbers: leftmost bit = 0 Negative numbers: leftmost bit = 1 To find a number’s complement – just flip all the bits and add 1 See graphical view – Fig. 2.3, p. 40.

Two’s-Comp Addition and Subtraction Rules Starting from 1000 (-8) on up, each successive 2’s comp number all the way to 0111 (+7) can be obtained by adding 1 to the previous one, ignoring any carries beyond the 4 th bit position Since addition is just an extension of ordinary counting, 2’s comp numbers can be added by ordinary binary addition! No different cases based on operands’ signs! Overflow possible –Occurs if result is out of range –To detect – happens if operands are the same sign but sum is a different sign of that of the operands

Modular Counting representation of Two’s Complements

Modular Counting representation of unsigned numbers Unsigned Numbers

Rules for addition and subtraction

DECIMAL CODES

Codes for Decimal Digits There are even codes for representing decimal digits. These codes use 4-bits for EACH decimal digits; it is NOT the same as converting from decimal to binary. BCD Code 0 = % = % = % = % = % = % = % = % = % = % 1001 In BCD code, each decimal digit simply represented by its binary equivalent. 96 = % = $ 96 (BCD code) Advantage: easy to convert Disadvantage: takes more bits to store a number: 255 = % = $ FF (binary code) 255 = % = $ 255 (BCD code) takes only 8 bits in binary, takes 12 bits in BCD.

Binary code for decimal numbers Any encoding needs at least 4 bits/decimal digit BCD (8421), a weighted code Packed BCD 2421 code –Self-complementing: the code for the 9s’ comp of any digit may be obtained by complementing the individual bits of the digit’s code word Excess 3 –Not a weighted code, but is also self-complementing –Since code follows standard binary counting sequence, standard binary counters can easily be made to count in excess-3

Biquinary code Uses more than 4 bits First 2 bits indicate whether the number is in the range 0-4 or 5-0 –One-hot Last 5 bits indicate which of the five numbers in the selected range is represented –Also one-hot Advantage: error-detection property. If any 1 bit in a code word is accidentally changed to the opposite value, the resulting code word doesn’t represent a decimal digit at all – flagged as error.

Codes for Characters Also need to represent Characters as digital data. The ASCII code (American Standard Code for Information Interchange) is a 7-bit code for Character data. Typically 8 bits are actually used with the 8th bit being zero or used for error detection (parity checking). 8 bits = 1 Byte. ‘A’ = % = $41 ‘&’ = % = $26 7 bits can only represent 2 7 different values (128). This enough to represent the Latin alphabet (A-Z, a-z, 0-9, punctuation marks, some symbols like $), but what about other symbols or other languages?

UNICODE UNICODE is a 16-bit code for representing alphanumeric data. With 16 bits, can represent 2 16 or different symbols. 16 bits = 2 Bytes per character. $ A A-Z $ A a-z Some other alphabet/symbol ranges $3400-3d2d Korean Hangul Symbols $ F Hiranga, Katakana, Bopomofo, Hangul $4E00-9FFF Han (Chinese, Japenese, Korean) UNICODE used by Web browsers, Java, most software these days.

Decimal codes Always two 1’s 0+3=3. 1+3=4 etc

GRAY CODES and mechanical encodings

A mechanical Encoding Disk Two bits change in natural binary code

Gray Code for decimal Digits Gray Code 0 = % = % = % = % = % = % = % = % = % = % 1000 A Gray code changes by only 1 bit for adjacent values. This is also called a ‘thumbwheel’ code because a thumbwheel for choosing a decimal digit can only change to an adjacent value (4 to 5 to 6, etc) with each click of the thumbwheel. This allows the binary output of the thumbwheel to only change one bit at a time; this can help reduce circuit complexity and also reduce signal noise.

Binary vs Gray Codes You should be able to design binary to Gray code converter in both directions

A mechanical disk for Gray Code Always one bit changes only

7 bit ASCII code You should be able to design a converter in both directions from any code to any other code!

Example of sequence generator machine with controlling counter machine

Controlling many devices with binary and one-hot codes

Error Correcting Codes

The concept of a hypercube

Even-parity and odd-parity codes

Space of codes for 7 bits with code words and non-code words

8-bit, distance 4 codes

Examples of Hamming Codes Hamming Codes

7 bit Hamming codes

Extended Hamming Codes

Two dimensional codes

Error-correcting code for a RAID system

Serial data transmission

Well-known codes for serial data transmission

Multiplication and Division Intro Multiplication and Division Intro

Binary multiplication Grammar school method for decimal: add a list of shifted multiplicands computed according to the digits of the multiplier Same method can be used in binary For two unsigned operands, the only possible values of the multiplier digits are 0 and 1 –Thus it’s trivial to form the shifted multiplicands

Binary multiplication in binary on a machine More convenient to add each shifted multiplicand as it is created to a partial product Will do an example. In general when we multiply an n-bit number by an m-bit number, the result requires at most n+m bits to express The shift-and-add algorithm requires m partial products and additions to obtain result, but the 1 st addition is trivial (adding to 0)

Long Division

Homework problem 1 Convert the following binary numbers to decimal:

Homework problem 2 Convert from decimal to binary:

Convert from Binary to Octal: Homework problem 3

Homework problem 4 Calculate (Let’s first convert these to binary as an exercise.) Verify in decimal 210 – 109, calculate first binary numbers. Verify.

Homework problem 5 1.Discuss how to convert hex, binary integers to Decimal 2.Discuss how to convert decimal integers to hex, binary 3.Discuss how to convert hex to binary, binary to Hex 4.Explain why N binary digits can represent 2 N values, unsigned integers 0 to 2 N -1.

sources Bob Reese Wakerly Other from internet