1 Number Systems Decimal, Binary, and Hexadecimal.

Slides:



Advertisements
Similar presentations
ICS312 Set 2 Representation of Numbers and Characters.
Advertisements

Representing Numbers: Integers
HEXADECIMAL NUMBERS Code
Chapter 2 : Number System
King Fahd University of Petroleum and Minerals
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Homework Hints Algorithms.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Data Representation ICS 233
1 Number Systems. 2 Numbers Each number system is associated with a base or radix – The decimal number system is said to be of base or radix 10 A number.
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.
COE 202: Digital Logic Design Number Systems Part 1
Number Systems Lecture 02.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
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
Computer Systems 1 Fundamentals of Computing Negative Binary.
Data Representation Number Systems.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
EEL-3705 TPS QUIZZES. Think - Pair - Share (TPS) Quizzes Think – Pair – Share –Think individually for one time units –Pair with partner for two time units.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Numbering systems.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Chapter 2 Number Systems + Codes. Overview Objective: To use positional number systems To convert decimals to binary integers To convert binary integers.
ICS312 Set 1 Representation of Numbers and Characters.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
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.
Positional Number Systems
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
Operations on Bits Arithmetic Operations Logic Operations
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
AEEE2031 Data Representation and Numbering Systems.
1 Review on Number Systems Decimal, Binary, and Hexadecimal.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
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=
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
© Prepared By: Razif Razali 1 CHAPTER TWO TCS1023 NUMBERING SYSTEM.
Computer Organization 1 Data Representation Negative Integers.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
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.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
Week 1(Number System) Muhammad Ammad uddin Logic Design Lab I (CEN211)
Data Representation COE 308 Computer Architecture
Binary & Hex Review.
Design of Digital Circuits Reading: Binary Numbers
Data Representation ICS 233
Data Representation.
Number Systems.
Data Representation COE 301 Computer Organization
Numbering System TODAY AND TOMORROW 11th Edition
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Number Systems Rayat Shikshan Sanstha’s
Data Representation ICS 233
Number Systems Rayat Shikshan Sanstha’s
Numbers and Arithmetic and Logical Operation
Binary & Hex Review.
Data Representation COE 308 Computer Architecture
Presentation transcript:

1 Number Systems Decimal, Binary, and Hexadecimal

2 Base-N Number System Base N N Digits: 0, 1, 2, 3, 4, 5, …, N-1 Example: 1045 N Positional Number System Digit d o is the least significant digit (LSD). Digit d n-1 is the most significant digit (MSD).

3 Decimal Number System Base 10 Ten Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: Positional Number System Digit d 0 is the least significant digit (LSD). Digit d n-1 is the most significant digit (MSD).

4 Binary Number System Base 2 Two Digits: 0, 1 Example: Positional Number System Binary Digits are called Bits Bit b o is the least significant bit (LSB). Bit b n-1 is the most significant bit (MSB).

5 Definitions nybble = 4 bits byte = 8 bits (short) word = 2 bytes = 16 bits (double) word = 4 bytes = 32 bits (long) word = 8 bytes = 64 bits 1K (kilo or “kibi”) = 1,024 1M (mega or “mebi”) = (1K)*(1K) = 1,048,576 1G (giga or “gibi”) = (1K)*(1M) = 1,073,741,824

6 Hexadecimal Number System Base 16 Sixteen Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Example: EF56 16 Positional Number System A 1011 B 1100 C 1101 D 1110 E 1111 F

7 Collaborative Learning Learning methodology in which students are not only responsible for their own learning but for the learning of other members of the group.

8 Think - Pair - Share (TPS) Quizzes Think – Pair – Share –Think individually for one time units –Pair with partner for two time units –Share with group for one and half time units –Report results

9 Quiz 1-A (Practice) Assemble in groups of 4 Question: Convert the following binary number into its decimal equivalent:

10 Quiz 1-A (Practice) THINK One Unit (e.g. 30 Seconds)

11 Quiz 1-A (Practice) PAIR Two Units (e.g. 60 Seconds)

12 Quiz 1-A (Practice) SHARE 1.5 units (e.g. 45 Seconds)

13 Quiz 1-A (Practice) Report Write names of all group members and the consensus answer on one sheet of paper. All sheets will be collected. One will be picked at random to read to the class. All papers will be graded!

14 Quiz 1-A Solution Convert the following number into base 10 decimal:

15 Quiz 1-B Convert the following number into base 10 decimal:

16 Collaborative Learning Think for 30 seconds Pair for 1 minute Share for 45 seconds Report

17 Quiz 1-B Solution Convert the following number into base 10 decimal: = 1· · · · ·16 0 = = 65, = 65,793

18 TPS Quiz 2

19 Binary Addition Single Bit Addition Table = = = = 10 N ote “carry”

20 Hex Addition 4-bit Addition = = C = F F + E = 1D N ote “carry”

21 Hex Digit Addition Table ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF ABCDEF AABCDEF BBCDEF A CCDEF A1B DDEF A1B1C EEF A1B1C1D FF A1B1C1D1E

22 TPS Quiz 3

23 Complements 1’s complement –To calculate the 1’s complement of a binary number just “flip” each bit of the original binary number. –E.g. 0  1, 1  0 – 

24 Complements 2’s complement –To calculate the 2’s complement just calculate the 1’s complement, then add  = –Handy Trick: Leave all of the least significant 0’s and first 1 unchanged, and then “flip” the bits for all other digits. Eg: >

25 Complements Note the 2’s complement of the 2’s complement is just the original number N –EX: let N = –2’s comp of N = M = –2’s comp of M = = N

26 Two’s Complement Representation for Signed Numbers Let’s introduce a notation for negative digits: –For any digit d, define d = −d. Notice that in binary, where d  {0,1}, we have: Two’s complement notation: –To encode a negative number, we implicitly negate the leftmost (most significant) bit: E.g., 1000 = (−1)000 = −1· · · ·2 0 = −8

27 Negating in Two’s Complement Theorem: To negate a two’s complement number, just complement it and add 1. Proof (for the case of 3-bit numbers XYZ):

28 Signed Binary Numbers Two methods: –First method: sign-magnitude Use one bit to represent the sign –0 = positive, 1 = negative Remaining bits are used to represent the magnitude Range - (2 n-1 – 1) to 2 n where n=number of digits Example: Let n=4: Range is –7 to 7 or 1111 to 0111

29 Signed Binary Numbers Second method: Two’s-complement Use the 2’s complement of N to represent -N Note: MSB is 0 if positive and 1 if negative Range - 2 n-1 to 2 n-1 -1 where n=number of digits Example: Let n=4: Range is –8 to 7 Or 1000 to 0111

30 Signed Numbers – 4-bit example Decimal 2’s comp Sign-Mag Pos 0

31 Signed Numbers-4 bit example Decimal 2’s comp Sign-Mag N/A (= +0) 1000

32 Notes: “Humans” normally use sign-magnitude representation for signed numbers –Eg: Positive numbers: +N or N – Negative numbers: -N Computers generally use two’s-complement representation for signed numbers –First bit still indicates positive or negative. –If the number is negative, take 2’s complement to determine its magnitude Or, just add up the values of bits at their positions, remembering that the first bit is implicitly negative.

33 Example Let N=4: two’s-complement What is the decimal equivalent of Since msb is 0, number is positive = 4+1 = What is the decimal equivalent of = Since MSB is one, number is negative Must calculate its 2’s complement = −(0010+1)= − or −3 10

34 Very Important!!! – Unless otherwise stated, assume two’s- complement numbers for all problems, quizzes, HW’s, etc. The first digit will not necessarily be explicitly underlined.

35 TPS Quizzes 5-7

36 Arithmetic Subtraction Borrow Method –This is the technique you learned in grade school –For binary numbers, we have – = = = = 1 w ith a “borrow” 1

37 Binary Subtraction Note: –A – (+B) = A + (-B) –A – (-B) = A + (-(-B))= A + (+B) –In other words, we can “subtract” B from A by “adding” –B to A. –However, -B is just the 2’s complement of B, so to perform subtraction, we 1. Calculate the 2’s complement of B 2. Add A + (-B)

38 Binary Subtraction - Example Let n=4, A= (4 10 ), and B= (2 10 ) Let’s find A+B, A-B and B-A  (4) 10  (2) A+B

39 Binary Subtraction - Example  (4) 10  (2) A-B  (4) 10  (-2) 10 A+ (-B) “Throw this bit” away since n=4

40 Binary Subtraction - Example  (2) 10  (4) B-A  (2) 10  (-4) 10 B + (-A) = = -2 10

41 “16’s Complement” method The 16’s complement of a 16 bit Hexadecimal number is just: = – N 16 Q: What is the decimal equivalent of B2CE 16 ?

42 16’s Complement Since sign bit is one, number is negative. Must calculate the 16’s complement to find magnitude. = – B2CE 16 = ????? We have B2CE

43 16’s Complement FFF B2CE 23D4

44 16’s Complement So, – B2CE 16 = 4D32 16 = 4×4, × × = 19, Thus, B2CE 16 (in signed-magnitude) represents -19,

45 Sign Extension

46 Sign Extension Assume a signed binary system Let A = 0101 (4 bits) and B = 010 (3 bits) What is A+B? –To add these two values we need A and B to be of the same bit width. –Do we truncate A to 3 bits or add an additional bit to B?

47 Sign Extension A = 0101 and B=010 Can’t truncate A!! Why? –A: > 101 –But 0101 <> 101 in a signed system –0101 = +5 –101 = -3

48 Sign Extension Must “sign extend” B, so B becomes 010 -> 0010 Note: Value of B remains the same So 0101 (5) (2) (7) Sign bit is extended

49 Sign Extension What about negative numbers? Let A=0101 and B=100 Now B = 100  1100 Sign bit is extended 0101 (5) (-4) (1) Throw away

50 Why does sign extension work? Note that: (−1) = 1 = 11 = 111 = 1111 = 111…1 –Thus, any number of leading 1’s is equivalent, so long as the leftmost one of them is implicitly negative. Proof: 111…1 = −(111…1) = = −(100…0 − 11…1) = −(1) So, the combined value of any sequence of leading ones is always just −1 times the position value of the rightmost 1 in the sequence. 111…100…0 = (−1)·2 n n

51 Number Conversions

52 Decimal to Binary Conversion Method I: Use repeated subtraction. Subtract largest power of 2, then next largest, etc. Powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2 n Exponent: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, n n2n

53 Decimal to Binary Conversion Suppose x = Subtract 1024: (2 10 ) = 540  n=10 or 1 in the (2 10 )’s position Thus: = ( ) 2 Subtract 512: (2 9 ) = 28  n=9 or 1 in the (2 9 )’s position Subtract 16: (2 4 ) = 12  n=4 or 1 in (2 4 )’s position Subtract 8:12 – 8 (2 3 ) = 4  n=3 or 1 in (2 3 )’s position Subtract 4:4 – 4 (2 2 ) = 0  n=2 or 1 in (2 2 )’s position 2 8 =256, 2 7 =128, 2 6 =64, 2 5 =32 > 28, so we have 0 in all of these positions

54 Decimal to Binary Conversion Method II: Use repeated division by radix. 2 | R = 0 2|_____ 391 R = 0 2|_____ 195 R = 1 2|_____ 97 R = 1 2|_____ 48 R = 1 2|_____ 24 R = 0 2|__24_ 12 R = 0 2|_____ 6 R = 0 2|_____ 3 R = 0 2|_____ 1 R = 1 2|_____ 0 R = 1  Collect remainders in reverse order

55 Binary to Hex Conversion 1.Divide binary number into 4-bit groups 2. Substitute hex digit for each group Pad with 0’s If unsigned number 61C 16 Pad with sign bit if signed number

56 Hexadecimal to Binary Conversion Example 1.Convert each hex digit to equivalent binary (1 E 9 C) 16 ( ) 2

57 Decimal to Hex Conversion Method II: Use repeated division by radix. 16 | R = 12 = C 16|_____ 6 R = 1 16|_____ 0 R = 6  N = 61C 16