By the end of the lecture, you should be able to:

Similar documents
LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

The string of digits in the binary number system represents the quantity

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Number Representation

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Systems I: Computer Organization and Architecture

Solution for Homework 2

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

CSI 333 Lecture 1 Number Systems

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Number and codes in digital systems

CPEN Digital Logic Design Binary Systems

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Numbering Systems. InThisAppendix...

HOMEWORK # 2 SOLUTIO

Lecture 2. Binary and Hexadecimal Numbers

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Binary Numbers. Binary Octal Hexadecimal

Lecture 11: Number Systems

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

2011, The McGraw-Hill Companies, Inc. Chapter 3

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Chapter 1: Digital Systems and Binary Numbers

NUMBER SYSTEMS. 1.1 Introduction

Useful Number Systems

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

CS201: Architecture and Assembly Language

Computer Science 281 Binary and Hexadecimal Review

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Chapter 2. Binary Values and Number Systems

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Binary Numbering Systems

Base Conversion written by Cathy Saxton

Number Systems. Introduction / Number Systems

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Chapter 4: Computer Codes

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Binary, Hexadecimal, Octal, and BCD Numbers

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Binary Representation

Data Storage 3.1. Foundations of Computer Science Cengage Learning

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Digital Logic Design. Introduction

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Section 1.4 Place Value Systems of Numeration in Other Bases

CS321. Introduction to Numerical Methods

DNA Data and Program Representation. Alexandre David

THE BINARY NUMBER SYSTEM

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

Number Systems and Radix Conversion

COMPSCI 210. Binary Fractions. Agenda & Reading

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Binary Adders: Half Adders and Full Adders

Chapter 1. Binary, octal and hexadecimal numbers

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Chapter 5. Binary, octal and hexadecimal numbers

COMBINATIONAL CIRCUITS

3. Convert a number from one number system to another

Lecture 8: Binary Multiplication & Division

BINARY CODED DECIMAL: B.C.D.

A Step towards an Easy Interconversion of Various Number Systems

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

The programming language C. sws1 1

=

MACHINE INSTRUCTIONS AND PROGRAMS

NUMBER SYSTEMS. William Stallings

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

2.2 Scientific Notation: Writing Large and Small Numbers

CHAPTER 5 Round-off errors

Memory is implemented as an array of electronic switches

Digital codes. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

The use of binary codes to represent characters

Counting in base 10, 2 and 16

Numerical Matrix Analysis

The Answer to the 14 Most Frequently Asked Modbus Questions

The New IoT Standard: Any App for Any Device Using Any Data Format. Mike Weiner Product Manager, Omega DevCloud KORE Telematics

Graphing Calculator Workshops

THE EXACT DOT PRODUCT AS BASIC TOOL FOR LONG INTERVAL ARITHMETIC

Activity 1: Using base ten blocks to model operations on decimals

Decimal Number (base 10) Binary Number (base 2)

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Let s put together a Manual Processor

Positional Numbering System

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

Computer Science PLUS I Volume 1 : Concepts Government of Tamilnadu

Exponents, Radicals, and Scientific Notation

Transcription:

Extra Lecture: Number Systems Objectives - To understand: Base of number systems: decimal, binary, octal and hexadecimal Textual information stored as ASCII Binary addition/subtraction, multiplication Binary logical operations Unsigned and signed binary number systems Fixed point binary representations Floating point representations By the end of the lecture, you should be able to: Convert between numbers represented in different bases Convert between fixed point and floating point numbers Perform simple binary arithmetic and logical operations Read and interpret hexadecimal numbers with reasonable speed Extra Lecture - 1 Decimal number system We are familiar with decimal number representation. For example: The value of this number is calculated as: In general, the relationship between the contribution of a digit, its position, and the base of the system is given by: Usually, we restrict DIGIT BASE - 1 Extra Lecture - 2

The bases of a number system There is no reason why one should be restricted to using base-1 (decimal) numbers only. Digital computers use a binary number system where the base (or radix) is 2: For example, the value of this binary number is: Extra Lecture - 3 Converting decimal integers to binary Repeatedly divide the decimal number by 2 (the base of the binary system). Division by 2 will either give a remainder of 1 or. Collecting the remainders (LSB first!) gives the binary answer. Convert 11 1 into binary 2 11 2 5 r 1 2 2 r 1 2 1 r 2 r 1 Answer: 1 1 1 Extra Lecture - 4

Octal and hexadecimal number systems run out of normal digit symbols Extra Lecture - 5 Nibbles, Bytes, Words Internal datapaths inside computers could be different width - for example 4-bit, 8-bit, 16-bit or 32-bit. For example: ARM processor uses 32-bit internal datapath WORD = 32-bit for ARM (byte and nibble are architecture independent) 32 24 23 16 15 8 7 MSB LSB Byte Nibble Word Extra Lecture - 6

Hexadecimal representation Convenient to divide any size of binary numbers into nibbles Represent each nibble as hexadecimal think of the human! Example: 1 111 11 111 1 11 1111 4 D 6 B 8 3 F This is possible because 16 is a power of 2 Converting from decimal to hexadecimal is the same as converting to binary, except, divide by 16 instead of 2: 16 237 16 14 r 13 r 14 Answer: E D h Extra Lecture - 7 Representing Text in ASCII Textual information must also be stored as binary numbers. Each character is represented as a 7-bit number known as ASCII codes (American Standard Code for Information Interchange) For example, A is represented by 41 h and a by 61 h b 3 -b b 6 -b 4 Extra Lecture - 8

Signed numbers So far, numbers are assumed to be unsigned (i.e. positive) How to represent signed numbers? Solution 1: Sign-magnitude - Use one bit to represent the sign, the remain bits to represent magnitude = +ve 1 = -ve 7 s 6 magnitude +27 = 1 111 b -27 = 11 111 b Advantage: easy human reasoning it s what we use Problem: addition and subtraction require quite complex circuits Extra Lecture - 9 Two s complement Solution 2: Two s complement represent a negative number x by the number 2^N + x, in an n-bit representation: Example: Encode 27 in 8 bit two s complement 256 27 = 229 229 1 = 111 11 b So long as we only want to represent numbers with magnitude less than 2^(N-1), the MSB is still the sign bit Example: Encode 27 in 8 bit two s complement 27 1 = 1 111 b Extra Lecture - 1

Two s complement Another view of two s complement is to represent a negative number by taking its magnitude, inverting all bits and adding one: Positive number Invert all bits Add 1 +27 = 1 111 b 111 1 b -27 = 111 11 b Why is this the same? Inverting all bits is the same as subtracting the number from 11.1: All ones Positive number Subtraction 1111 1111 b +27 = 1 111 b 111 1 b So inverting and then adding one is the same as subtracting from 11.1 + 1 = 1. = 2^N All ones Add 1 1111 1111 b 1 b Extra Lecture - 11 Two s complement A third (and final!) way to view two s complement is that the weight of position i is 2^i except the MSB, which has negative weight x = b N 1 N 2 1 N 12 + bn 22 + + b1 2 + b 2 Why is this the same? If we interpreted this as an unsigned number, it would be y = b -27 = 111 11 b = -128 + 64 + 32 + 4 + 1 N 1 N 2 1 N 12 + bn 2 2 + + b1 2 + b 2 If x is negative, sign bit b N-1 is 1, so difference is y x = 2^N, i.e. y = 2^N + x Extra Lecture - 12

Why 2 s complement representation? If we represent signed numbers in 2 s complement form, subtraction is the same as addition to the (2 s complemented) number (if we ignore any carry out) 27 1 111 b - 17 1 1 b + 1 11 b +27 1 111 b + - 17 111 1111 b +1 11 b Note that the range for 8-bit unsigned and signed numbers are different. 8-bit unsigned: +255 8-bit 2 s complement signed number: -128 +127 Extra Lecture - 13 Sign Extension How to translate an 8-bit 2 s complement number to a 16-bit 2 s complement number? -2 7 2 6 2 s duplicate sign bit -2 15 s 2 6 2 s... This operation is known as sign extension. Result is the same: trivially so for positive numbers Extra Lecture - 14

Sign Extension For negative numbers, consider a 1-bit sign extension -2 7 1 2 6 2 difference -256-2 8 2 7 1 1 difference 128-(-128) = 256 2 Total difference = i.e. same number! Extra Lecture - 15 Fixed point representation So far, we have concentrated on integer representation with the fractional part. There is an implicit binary point to the right: N-1 S In general, the binary point can be in the middle of the word (or off the end!) N-1 S binary point implicit binary point Extra Lecture - 16

Idea of floating point representation Although fixed point representation can cope with numbers with fractions, the range of values that can represented is still limited. Alternative: use the equivalent of scientific notation, but in binary: For example: number = s x m x 2 e sign mantissa exponent 1.5 in fixed point 11.1 b Move binary point to left 1.11 b x 2 3 1.5 = 1.3125 x 8 Extra Lecture - 17 IEEE-754 standard floating point 32-bit single precision floating point: single precision 31 3 23 22 S 8-bit exp 23-bit frac x = 1 s 1.175 1 2 38 exp 127 < x 1. frac < 1.7 1 38 MSB is sign-bit (same as fixed point) 8-bit exponent in bias-127 integer format (i.e. store 127+exponent) 23-bit to represent only the fractional part of the mantissa. The MSB of the mantissa is ALWAYS 1, therefore it is not stored Extra Lecture - 18