Number Systems Computer Science 210 Computer Organization.

Slides:



Advertisements
Similar presentations
A-Level Computing#BristolMet Session Objectives#9 express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal; describe and use two’s.
Advertisements

HEXADECIMAL NUMBERS Code
Computer Science 101 Binary Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions.
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Representations Example: Numbers –145 –CVL – –91 –
Assembly Language and Computer Architecture Using C++ and Java
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
ECE 301 – Digital Electronics Number Systems and Conversion, Binary Arithmetic, and Representation of Negative Numbers (Lecture #10) The slides included.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Computer Science 210 Computer Organization Floating Point Representation.
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.
Computer Fluency Binary Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Computer Science 101 Number Systems. Humans Decimal Numbers (base 10) Decimal Numbers (base 10) Sign-Magnitude (-324) Sign-Magnitude (-324) Decimal Fractions.
Binary Number Systems.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Binary Representation and Computer Arithmetic
The Binary Number System
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Simple Data Type Representation and conversion of numbers
Lecture 5.
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.
Computer Science 111 Fundamentals of Programming I Number Systems.
IT253: Computer Organization
Eng. Mohammed Timraz Electronics & Communication Engineer University of Palestine Faculty of Engineering and Urban planning Software Engineering Department.
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,
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
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.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Number Systems and Codes. CS2100 Number Systems and Codes 2 NUMBER SYSTEMS & CODES Information Representations Number Systems Base Conversion Negative.
ECE 331 – Digital System Design
The Teacher CP4 Binary and all that… CP4 Revision.
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
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.
The Teacher CP4 Binary and all that… CP4 Revision.
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 2: Number Systems & x86 Instructions Constantine D. Polychronopoulos Professor, ECE Office: 463.
Number Representation (Part 1) Computer Architecture (Fall 2006)
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Numbers in Computers.
Number Representation (Part 2) Computer Architecture (Fall 2006)
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
DATA REPRESENTATION Data Types Complements Fixed Point Representations
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Computer Science 210 Computer Organization
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Computer Science 210 Computer Organization
Data Representation Integers
CSE 102 Introduction to Computer Engineering
University of Gujrat Department of Computer Science
CS1010 Programming Methodology
Computer Science 210 Computer Organization
Data Representation Data Types Complements Fixed Point Representation
Fundamentals of Programming I Number Systems
Data Representation in Computer Systems
Computer Science 210 Computer Organization
Number Representation
Chapter 6: Computer Arithmetic
Presentation transcript:

Number Systems Computer Science 210 Computer Organization

People Decimal Numbers (base 10) Sign-Magnitude (-324) Decimal Fractions (23.27) Letters for text

Computers Binary Numbers (base 2) Sign-magnitude Binary fractions and floating point ASCII codes for characters (A  65)

Why binary? Information is stored in computer via voltage levels. Using decimal would require 10 distinct and reliable levels for each digit. This is not feasible with reasonable reliability and financial constraints. Everything in computer is stored using bits: numbers, text, programs, pictures, sounds, videos,...

Decimal: Non-negatives Base 10 Uses decimal digits: 0, 1,..., 9 Positional System - position gives power Example: 3845 = 3x x x x10 0 Positions: …543210

Binary: Non-negatives Base 2 Uses binary digits (bits): 0,1 Positional system Example: 1101 = 1x x x x2 0

Conversions ExternalInternal (For people) (For computer) A People want to see and enter numbers in decimal. Computers must store and compute with bits.

Binary to Decimal Conversion Algorithm: –Expand binary number using positional scheme. –Perform computation using decimal arithmetic. Example:  1x x x x x2 0 = = = 25 10

Decimal to Binary - Algorithm 1 Algorithm: While N  0 do Set N to N/2 (whole part) Record the remainder (1 or 0) Set A to remainders in reverse order

Decimal to binary - Example Example: Convert to binary N Rem N Rem =

Decimal to Binary - Algorithm 2 Algorithm: Set A to 0 (all bits 0) While N  0 do Find largest P with 2 P  N Set bit in position P of A to 1 Set N to N - 2 P

Decimal to binary - Example Example: Convert to binary N Power P A =

Binary Addition One bit numbers: | | 1 10 Example (53) (45) (98)

Overflow In a given type of computer, the size of integers is a fixed number of bits. 16 or 32 bits are popular choices It is possible that addition of two n bit numbers yields a result requiring n+1 bits. Overflow is the term for an operation whose results exceeds the size allowed for a number.

Negatives: Sign-Magnitude With a fixed number of bits, say N –The leftmost bit is used to give the sign 0 for positive number 1 for negative number –The other N-1 bits are for the magnitude Example: -25 with 8 bit numbers – Sign: 1 since negative – Magnitude: for 25 – 8-bit result: Note: This would be 153 as a positive.

Ranges for N-bit numbers Unsigned (positive) – 0000…00 or 0 – 1111…11 which is 2 N -1 – For N=8, Sign-magnitude – 1111…11which is -(2 N-1 -1) – 0111…11which is 2 N-1 -1 – For N=8, -127 to ’ s Complement – 1000…00 which is -2 N-1 – 0111…11which is 2 N – For N=8, -128 to 127

Octal Numbers Base 8 Digits 0,1,2,3,4,5,6,7 Not so many digits as binary Easy to convert to and from binary Often used by people who need to see the internal representation of data, programs, etc.

Octal Conversions Octal to Binary – Simply convert each octal digit to a three bit binary number. – Example: = Binary to Octal – Starting at right, group into 3 bit groups – Convert each group to an octal digit – Example = =

Hexadecimal Base 16 Digits 0,…,9,A,B,C,D,E,F Hexadecimal  Binary – Just like Octal, only use 4 bits per digit. Example: 98C3 16 = Example = = 34EB

Sign-Magnitude: Pros and Cons Pro: –Easy to comprehend –Easy to convert Con: –Addition complicated (expensive) If signs same then … else if positive part larger … –Two representations of 0

Negatives: Two ’ s complement With N bit numbers, to compute negative –Invert all the bits –Add 1 Example: -25 in 8-bit two ’ s complement – 25  – Invert bits: – Add 1:

2 ’ s Complement: Pros and Cons Con: –Not so easy to comprehend –Human must convert negative to identify Pro: –Addition is exactly same as for positives No additional hardware for negatives, and subtraction. –One representation of 0

2 ’ s Complement: Examples Compute negative of -25 (8-bits) – We found -25 to be – Invert bits: – Add 1: – Recognize this as 25 in binary Add -25 and 37 (8-bits) – (-25) ( 37) (1) – Recognize as 12

Facts about 2 ’ s Complement Leftmost bit still tells whether number is positive or negative as with sign-magnitude 2 ’ s complement is same as sign magnitude for positives

2 ’ s complement to decimal (examples) Assume 8-bit 2 ’ s complement: – X = X = = = = 39 (decimal) So, X = -39 – X = Since X is positive, we have X = = 89