Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 2 Number Systems.

Slides:



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

Lecture - 2 Number systems and computer data formats
Chapter 1 Digital Systems and Numbers System
Digital Fundamentals Floyd Chapter 2 Tenth Edition
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Data Representation in Computers
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Data Storage. SIGN AND MAGNITUDE Storing and representing numbers.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Binary Representation and Computer Arithmetic
(2.1) Fundamentals  Terms for magnitudes – logarithms and logarithmic graphs  Digital representations – Binary numbers – Text – Analog information 
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Computers Organization & Assembly Language
EKT 121 / 4 ELEKTRONIK DIGIT 1 CHAPTER 1 : INTRODUCTION.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
Chapter 3 Data Representation
Binary Arithmetic & Data representation
Data Representation and Computer Arithmetic
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
ICS312 Set 1 Representation of Numbers and Characters.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
CPU Internal memory I/O interface circuit System bus
The Teacher CP4 Binary and all that… CP4 Revision.
Dr. Ahmed Telba EE208: Logic Design Lecture# 1 Introduction & Number Systems.
Number systems, Operations, and Codes
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
Data Representation, Number Systems and Base Conversions
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Digital Systems and Binary Numbers
Data Representation Bits, Bytes, Binary, Hexadecimal.
Binary01.ppt Decimal Decimal: Base 10 means 10 Unique numerical digits ,00010,000 Weight Positions 3,
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
School of Computer and Communication Engineering, UniMAP Mohd ridzuan mohd nor DKT 122/3 - DIGITAL SYSTEM I Chapter.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Computer Math CPS120 Introduction to Computer Science Lecture 7.
CHAPTER 3 BINARY NUMBER SYSTEM. Computers are electronic machines which operate using binary logic. These devices use two different values to represent.
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.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Dr. Clincy Slide 1 CS Chapter 2 (Part 1 of 3) Dr. Clincy Professor of CS Ch 2 Appendix pages will not be on the exam – already covered this.
CS2100 Computer Organisation
Some basic concepts underlying computer archi­tecture
Digital Logic and Computer Organization
Number Systems and Binary Arithmetic
Digital Systems and Binary Numbers
Integer Real Numbers Character Boolean Memory Address CPU Data Types
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CHAPTER 1 : INTRODUCTION
Dr. Clincy Professor of CS
Digital Systems and Binary Numbers
Introduction The term digital is derived from the way computers perform operation, by counting digits. Application of digital technology: television, communication.
CSE 102 Introduction to Computer Engineering
Chapter 3 Data Representation
University of Gujrat Department of Computer Science
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Dr. Clincy Professor of CS
Number Systems Lecture 2.
Presentation transcript:

Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 2 Number Systems

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 2 Outline Numeral Systems Computer Data Storage Units Numeral Systems Conversion Calculations in Number Systems Signed Integer Representation Fractional and Real Numbers ASCII Codes

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 3 Numeral Systems Decimal number system (base 10) Binary number system (base 2) – Computers are built using digital circuits – Inputs and outputs can have only two values: 0 and 1 1 or True (high voltage) 0 or false (low voltage) – Writing out a binary number such as is tedious, and prone to errors Octal and hex are a convenient way to represent binary numbers, as used by computers – Octal number system (base 8) – Hexadecimal number system (base 16)

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 4 Numeral Systems HexadecimalOctalBinaryDecimal A (decimal value of 10) B (decimal value of 11) C (decimal value of 12) D (decimal value of 13) E (decimal value of 14) F (decimal value of 15) Base B : 0 ≤ digit ≤ B Base 10 : 0 ≤ digit ≤ 9 (10 -1) Base 2 : 0 ≤ digit ≤ 1 (2-1) Base 8 : 0 ≤ digit ≤ 7 (8 -1) Base 16 : 0 ≤ digit ≤ 15 (16 -1)

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 5 Computer Data Storage Units Bit – Each bit can only have a binary digit value: 1 or 0 – basic capacity of information in computer – A single bit must represent one of two states: 2 1 =2 How many state can encode by N bit? 01OR

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 6 Binary Encoding

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 7 Computer Data Storage Units Byte: A sequence of eight bits or binary digits – 2 8 = 256 (0..255) – smallest addressable memory unit ……………………… Bit Order One Bit MemoryAddress …

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 8 Computer Data Storage Units Kilo byte: 2 10 = 1024 – 2 11 = 2 K = 2048 – 2 16 = 64 K = Mega byte: 2 20 = 1024 × 1024 – 2 21 = 2 M Giga byte: 2 30

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 9 Numeral Systems Conversion Covert from Base-B to Base-10: – (A) B = (?) 10 (4173) 10 = (4173) 10 ( ) 2 = (?) 10 (0756) 8 = (?) 10 (3b2) 16 = (?) 10 Convert from Base-10 to Base-B: – (N) 10 = (?) B (4173) 10 = (?) 2 (494) 10 = (?) 8 (946) 10 = (?) 16

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 10 Covert from Base-B to Base-10 1.Define bit order Example : Base-2 to Base

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 11 Covert from Base-B to Base-10 2.Calculate Position Weight – B bit order Example : Base-2 to Base B = 2 … Position Weight Decimal Point s10s1s1/10s1/100s

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 12 Covert from Base-B to Base-10 3.Multiplies the value of each digit by the value of its position weight * * * * 0 1*11*1 2*12*1 4*04*0 8*18*1 16 * 0 32 * 0 64 * * *

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 13 Covert from Base-B to Base-10 4.Adds the results of each section * * * * 0 1*11*1 2*12*1 4*04*0 8*18*1 16 * 0 32 * 0 64 * *

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 14 Covert from Base-B to Base-10 Examples: (a n-1 a n-2 … a 0. a -1 … a -m ) B = (N) 10 N = (a n-1 * B n-1 ) + (a n-2 * B n-2 ) + … + (a 0 * B 0 ) + (a -1 * B -1 ) + … + (a -m * B –m ) (4173) 10 = (4 * 10 3 ) + (1 * 10 2 ) + (7*10 1 ) + (3*10 0 ) = (4173) 10 (0756) 8 = (0 * 8 3 ) + (7 * 8 2 ) + (5*8 1 ) + (6*8 0 ) = (494) 10 (3b2) 16 = (3 * 16 2 ) + (11*16 1 ) + (2*16 0 ) = (946) 10 (2E6.A3) 16 = (2 * 16 2 ) + (14*16 1 ) + (6*16 0 ) + (10 * (1 / 16)) + (3 * (1 / (16 * 16))) = (?)

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 15 Convert from Base-10 to Base-B (N) 10 = ( a n-1 a n-2 … a 0. a -1 … a -m ) B Integer part Fraction part 1.Convert integer part to Base-B – Consecutive divisions 2.Convert fraction part to Base-B – Consecutive multiplication

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 16 Convert Integer Part to Base-B Repeat until the quotient reaches 0 Write the reminders in the reverse order – Last to first Examples: ( 25 ) 10 = (11001) 2

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 17 Convert Integer Part to Base-B Examples: (494) 10 = (756) (946) 10 = ( 3B2 ) 16

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 18 Convert Fraction Part to Base-B Do multiply fraction part by B (the result) drop the integer part of the result (new fraction) While (result = 0) OR (reach to specific precision) the integral parts from top to bottom are arranged from left to right after the decimal point

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 19 Convert Fraction Part to Base-B Example: – * 2 = 0.25 – 0.25 * 2 = 0.50 (0.125) 10 = (0.001) 2 – 0.50 * 2 = 1.00 – 0.00 * 2 =

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 20 Convert Fraction Part to Base-B Example: – 0.6 * 2 = 1.2 – 0.2 * 2 = 0.4 (0.6) 10 = (0.1001) 2 – 0.4 * 2 = 0.8 – 0.8 * 2 = 1.6 – 0.6 * 2 = …

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 21 Conversion binary and octal Binary to Octal – 2 3 = 8 – Each digit in octal format: 3 digits in binary format – If the number of digits is not dividable by 3, add additional zeros: = 043 = = = ( ) 2 = ( ) 2 = (23.64) a3a3 a2a2 a1a1 a0a0. a -1 a -2 Octal Binary

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 22 Conversion binary and octal Octal to Binary – Substitute each digit with 3 binary digits (5) 8 = (101) 2 (1) 8 = (001) 2 (51) 8 = ( ) 2 (23.61) 8 = ( ) 2

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 23 Conversion binary and Hexadecimal Binary to Hexadecimal – 2 4 = 16 – Each digit in octal format: 4 digits in binary format – If the number of digits is not dividable by 4, add additional zeros: 0 0 ( ) 16 = ( ) 16 = (7D.6) 2 7 D 6 a3a3 a2a2 a1a1 a0a0. a -1 a -2

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 24 Conversion binary and Hexadecimal Hexadecimal to Binary – Substitute each digit with 4 binary digits (F25.03) 16 = ( )

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 25 Conversion Octal binary Hexadecimal – (345) 8 = (E5) 16 – (345) 8 = ( ) 2 = ( ) 2 = (E5) E 5 – (3FA5) 16 = ( ) 2 = ( ) 2 = (037645) 8 = (37645) 8

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 26 Calculations in Numeral Systems Addition – Binary 1111carried digits (13) (23) (36) → → (1 + 1 ) 10 → (2) 10 = (10) 2

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 27 Calculations in Numeral Systems Addition – Hexadecimal – Octal BDA BDA 1B5E (8 + D ) 16 → (8 + 13) 10 = (21) 2 = (15) (4 + 6 ) 10 → (10) 10 = (12) 8

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 28 Calculations in Numeral Systems Subtraction – Binary 2 002Borrowed digits (13) (7) (6) (2) 10 = (10) Borrowed digit

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 29 Calculations in Numeral Systems subtraction – Hexadecimal – Octal = = = CF =

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 30 Signed Integer Representation Negative numbers must be encode in binary number systems Well-known methods –Sign-magnitude –One’s Complement –Two’s Complement Which one is better? –Calculation speed –Complexity of the computation circuit

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 31 Sign-magnitude One sign bit + magnitude bits – Positive: s = 0 – Negative: s= 1 – Range = {(-127) 10.. (+127) 10 } – Two ways to represent zero: (+0) (−0) – Examples: (+ 43) 10 = (- 43) 10 = How many positive and negative integers can be represented using N bits? – Positive: 2 N – Negative: 2 N s MagnitudeSign

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 32 Two’s Complement Negative numbers: 1.Invert all the bits through the number ~(0) = 1 ~(1) = 0 2.Add one Example: +1 = = ? – ~( ) → – → Only one zero ( ) Range = {127.. −128} Negative two's complement ( ) -( ) = -3 ~( ) + 1

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 33 ASCII Codes American Standard Code for Information Interchange – First decision: 7 bits for representation – Final decision: 8 bits for representation 256 characters ASCII (“P”) = (50) 16 ASCII (“=”) = (3D) 16 FEDCBA Hexadecimal SISOCRFFVTLFTABBSBELACKENQEOTETXSTXSOHNUL 0 USRSGSFSESCSUBEMCANETBSYNNAKDC4DC3DC2DC1DLE 1 /.-,+*()'&%$#"! 2 ?<=>;: _^[\]ZYXWVUTSRQP 5 onmlkjihgfedcba` 6 ~{|}zyxwvutsrqp 7 row number column number

Number Systems – Lecture 2 Sharif University of Technology Department of Computer Engineering 34 Summary Numeral Systems – Decimal, Binary, Octal, Hexadecimal Computer Data Storage Units – Bit, Byte, Kilo byte, Giga byte, Numeral Systems Conversion – Convert between different bases Calculations in Number Systems – Addition and subtraction Signed Integer Representation – Sing-magnitude: one sign bit + magnitude bits – Two’s complement : (-N) = ~(N) + 1 Fractional and Real Numbers ASCII Codes