 Instructor: Rob Nash  Readings: Berger, Chapter 1; Rosen, Chapter 3.

Slides:



Advertisements
Similar presentations
Data Representation COE 202 Digital Logic Design Dr. Aiman El-Maleh
Advertisements

DATA REPRESENTATION CONVERSION.
Number Theory and Cryptography
Chapter 2 Binary Values and Number Systems Chapter Goals Distinguish among categories of numbers Describe positional notation Convert numbers in.
Level ISA3: Information Representation
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
Chapter 02 Binary Values and Number Systems Nell Dale & John Lewis.
Number Systems and Arithmetic
 Binary Binary  Binary Number System Binary Number System  Binary to Decimal Binary to Decimal  Decimal to Binary Decimal to Binary  Octal and Hexadecimal.
Binary Numbers.
Fall 2002CMSC Discrete Structures1 Let us get into… Number Theory.
Real Numbers and the Decimal Number System
Binary and Hexadecimal Numbers
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
February 24, 2015Applied Discrete Mathematics Week 4: Number Theory 1 Modular Arithmetic Let a be an integer and m be a positive integer. We denote by.
CS105 INTRODUCTION TO COMPUTER CONCEPTS BINARY VALUES & NUMBER SYSTEMS Instructor: Cuong (Charlie) Pham.
MATH 224 – Discrete Mathematics
Numeral Systems Subjects: Numeral System Positional systems Decimal
Numbering Systems CS208.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Computer Science 111 Fundamentals of Programming I Number Systems.
1 Problem Solving using computers Data.. Representation & storage Representation of Numeric data The Binary System.
Chapter 2 Binary Values and Number Systems Chapter Goals Distinguish among categories of numbers Describe positional notation Convert numbers in.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Number Systems Ron Christensen CIS 121.
Integer Representation for People Computer Organization and Assembly Language: Module 3.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
CCE-EDUSAT SESSION FOR COMPUTER FUNDAMENTALS Date: Session III Topic: Number Systems Faculty: Anita Kanavalli Department of CSE M S Ramaiah.
Binary Values and Number Systems Chapter Goals Distinguish among categories of numbers Describe positional notation Convert numbers in other bases.
Number systems, Operations, and Codes
Binary Values and Number Systems
Positional Notation 642 in base 10 positional notation is:
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
Chapter 2 Number Systems: Decimal, Binary, and Hex.
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Octal & Hexadecimal Number Systems
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Chapter 2 Binary Values and Number Systems Chapter Goals Distinguish among categories of numbers Describe positional notation Convert numbers in.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 2 1Created by: Ms.Amany AlSaleh.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
Digital logic COMP214  Lecture 2 Dr. Sarah M.Eljack Chapter 1 1.
Binary Values. Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers.
1. Binary, Decimal, Hexadecimal and Octal. 2. Conversion between various number systems. Number Systems:
Prepared By: Norakmar Binti Mohd Nadzari CHAPTER 2 ARITHMETIC AND LOGIC UNIT.
Number Theory. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic principles of divisibility,
Cosc 2150: Computer Organization
Digital Electronics INTRODUCTION ANALOG VS DIGITAL NUMBER SYSTEMS.
CHAPTER 1 : INTRODUCTION
COMPUTING FUNDAMENTALS
Octal & Hexadecimal Number Systems
Octal & Hexadecimal Number Systems
Number Theory and Cryptography
Chapter 3 Data Representation
Number System conversions
Octal & Hexadecimal Number Systems
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
Number Systems and Binary Arithmetic
Introduction to IT By: Muhammed s. anwar.
Octal & Hexadecimal Number Systems
Digital Electronics and Microprocessors
Chapter 2: Number Systems
Presentation transcript:

 Instructor: Rob Nash  Readings: Berger, Chapter 1; Rosen, Chapter 3

 A set of steps in a specific order, or  A procedure for performing some (usually arithmetic) operation  These algorithms, adapted for use with binary, form the basis for computer arithmetic.

 In addition to arithmetic operations…  We’ll take a look at Euclid's Algorithm  An algorithm for finding the base b expansion of a positive integer for any base b  And, we’ll take some time to consider an algorithm’s performance

 We can represent numbers in other bases, however, often for convenience of manipulation or translation.  We’ll need to know base 2, since those are our machine’s symbols  We’ll also see that base 16 (hex) is useful for representing bit strings in a compact fashion

 Early tube & transistor technology functions much like a lightswitch  Today’s integrated circuits also offer “microswitches” as the basis for feedback loops (memory)  We could have had to manipulate numbers in base 3 if our early technology functioned accordingly  In fact, we’ll try out base 3 for fun

 965 = (9 * 10^2) + (6 * 10^1) + (5 * 10^0)  Just an expanded form that highlights the sum of products that compose this number ▪ Also highlights the base here, which is 10  In fact, we can use any int > 1 as a base when expressing integers, and we can convert between these bases  We’ll often use base 10 as the intermediary base when converting ▪ But, we can also convert from one base to another directly (16 -> 2)

 (101) base 2 is also a compact form of:  101 = (1 * 2^2) + (0 * 2^1) + (1 * 2^0 ) = 5  What about 1011?

 Let b be a positive integer greater than 1. If n is a positive integer, it can be uniquely expressed in the form:  n = a k b k + a k-1 b k-1 + … + a 1 b 1 + a 0 b 0

 Let b be a positive integer greater than 1. If n is a positive integer, it can be uniquely expressed in the form:  n = a k b k + a k-1 b k-1 + … + a 1 b 1 + a 0 b 0  Where k is a nonnegative integer  And a 0 - a k are nonnegative integers < b  This simply means our coefficients can’t exceed our base  And a k is not equal to 0  i.e. eliminate leading zeroes  The base b expansion of n is then (a k, a k-1,…, a 0 ) b  Base is indicated by subscript b

 The idea here: we can denote base b expansion of an integer n as (a k, a k-1,…, a 0 ) b  From this we can calculate the decimal expansion as n = a k b k + a k-1 b k-1 + … + a 1 b 1 + a 0 b 0  So, (245) 8 represents…  (2 * 8^2) + (4 * 8^1) + (5 * 8^0)  (2 * 64) + (4 * 8) + (5 * 1)  = 165

 Try to convert the following from the various bases to base 10  498 = (4 * 10^2) + (9 * 10^1) + (8 * 10^0)   (110) 2 = (? * 2^2) + (? * 2^1) + (? * 2^0 )  (201) 3 = (? * 3^?) + (0 * 3^?) + (1 * 3^? )

 (110) 2 = (1 * 2^2) + (1 * 2^1) + (0 * 2^0 )  (201) 3 = (2 * 3^2) + (0 * 3^1) + (1 * 3^0 )  (1111) 2 = ?  (0xCAFE) 16 = ?

 Lets use 2 as the base  The binary expansion of an integer, then, is just a string of bits  Lets consider first the decimal expansion of the integer that has “ ” as its binary expansion?  First, use the full form  Then, consider a quick counting trick

 Hex is quite useful in computer science, and we’ll soon see why  Hex symbols: {0,1,…,9,A,B,C,D,E,F}  Where A == 10, B == 11, …, F == 15  (0x01F) 16 = (0*16^2) + (1*16^1) + (15*16^0) = 31  (0xCAFE1) 16 = (12 * 16^4) + (10 * 16^3) + (15 * 16^2) + (14 * 16^1) + 1 = big base 10 int

 Consider (0xCAFE1) 16  Each hex symbol represents (2^4) unique symbols  Thus, a hex symbol neatly encodes 4 bits  Two hex symbols comprise a byte  So, if we can memorize all the bit patterns from (only 16 of them, to represent the integers 0-15), we can quickly convert from base 16 to base 2.

 0000 –  0001 –  0010 –  0011 –  0100 –  0101 –  0110 –  0111 –

 So far, this is our tool for converting some integer n from an arbitrary base b to base 10.  We know now how to translate from any base to decimal, but…  How do we translate from decimal to an arbitrary base b?  We can derive a second algorithm from Theorem 1, which accomplishes expansions in arbitrary bases  Binary expansions  Hexadecimal expansions  …

 Now lets consider this algorithm for constructing a base b expansion from a decimal integer.  With the two algorithms combined, we can go from base x to base 10, and then from base 10 to some other base y  And we’ll learn shortcuts to cut out the “middleman” along the way

 Lets see a Base b expansion of an integer n  Approach:  First, divide n by b to obtain a quotient q0 and a remainder r0. ▪ r0 is your least significant digit (rightmost digit)  Next, divide q0 by b to produce another quotient q1 and a remainder r1 ▪ r1 is your next least significant digit (second to rightmost)  Repeat until qx == 0

 Convert to n=31 to binary, b=2  31/2 = 15 r 1 //the rightmost bit  15/2 = 7 r 1  7/2 = 3 r 1  3/2 = 1 r 1  1/2 = 0 r 1 //the most significant bit

 Given n=165, convert to hexadecimal, b=16  165 / 16 = 10 r 5  10/ 16 = 0 r A  Answer: 0xA5

 Given n=241, find the binary expansion, b=2  241 / 2 = 120 r 1  120 / 2 = 60 r 0  60 / 2 = 30 r 0  30 / 2 = 15 r 0  15 / 2 = 7 r 1  7 / 2 = 3 r 1  3 / 2 = 1 r 1  1 / 2 = 0 r 1  Answer:  Now try converting this bit string to hex using our “shortcut”

 //invariant: b, n are positive ints  Procedure baseBExpansion(int n, int b) {  q = n  k = 0  while( q != 0 ) { ▪ a k = q mod b ▪ q = floor( q / b ) //if q & b are ints, no need for floor ▪ k = k + 1  }  return (a k-1 …a 1 a 0 ) b  }