CSEN102 Introduction to Computer Science

Similar documents
Week No. 06: Numbering Systems

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

We say that the base of the decimal number system is ten, represented by the symbol

12/31/2010. Digital Operations and Computations Course Notes. 01-Number Systems Text: Unit 1. Overview. What is a Digital System?

ENGIN 112 Intro to Electrical and Computer Engineering

NUMBERS AND CODES CHAPTER Numbers

Conversions between Decimal and Binary

Why digital? Overview. Number Systems. Binary to Decimal conversion

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

1 Computing System 2. 2 Data Representation Number Systems 22

Computer Number Systems

CHAPTER 2 NUMBER SYSTEMS

Binary addition example worked out

Number Systems. There are 10 kinds of people those that understand binary, those that don t, and those that expected this joke to be in base 2

Four Important Number Systems

ENG2410 Digital Design Introduction to Digital Systems. Fall 2017 S. Areibi School of Engineering University of Guelph

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

Numbers. Dr Hammadi Nait-Charif. Senior Lecturer Bournemouth University United Kingdom

of Digital Electronics

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology.

Counting in Different Number Systems

ENGIN 112 Intro to Electrical and Computer Engineering

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

Number Theory: Representations of Integers

CSE 241 Digital Systems Spring 2013

Number Bases. Ioan Despi. University of New England. August 4, 2013

Chapter 1 CSCI

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:

ECE380 Digital Logic. Positional representation

CISC 1400 Discrete Structures

3 The fundamentals: Algorithms, the integers, and matrices

THE LOGIC OF COMPOUND STATEMENTS

Decimal Addition: Remember to line up the decimals before adding. Bring the decimal straight down in your answer.

Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices. Integers & Algorithms (2.5)

REVIEW Chapter 1 The Real Number System

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:

4 Number Theory and Cryptography

What are binary numbers and why do we use them? BINARY NUMBERS. Converting decimal numbers to binary numbers

Digital Electronics Part 1: Binary Logic

Finding Prime Factors

CSE 20 DISCRETE MATH. Fall

Chapter 5. Number Theory. 5.1 Base b representations

Number System conversions

Introduction to digital systems. Juan P Bello

Section 1.2 Factors and Factor Operators

Chapter 9 - Number Systems

Discrete Mathematics GCD, LCM, RSA Algorithm

NUMBER. Here are the first 20 prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71.

Hakim Weatherspoon CS 3410 Computer Science Cornell University

TESTCRACKER CAT TOPPER s PROGRAM: QUANT. Factorial

Standard forms for writing numbers

Outline. policies for the first part. with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014

number to represent the problem.

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Introduction CSE 541

ECE260: Fundamentals of Computer Engineering

2.5 정수와알고리즘 (Integers and Algorithms)

Base-b representations of integers. (b 진법표현 ) Algorithms for computer arithmetic: Euclidean algorithm for finding GCD s.

hexadecimal-to-decimal conversion

Intermediate Math Circles February 14, 2018 Contest Prep: Number Theory

COT 3100 Applications of Discrete Structures Dr. Michael P. Frank

Students should be able to (a) produce a truth table from a given logic diagram

A number that can be written as, where p and q are integers and q Number.

Additive Numbering Systems and Numbers of Different Bases MAT 142 RSCC Scott Surgent

Unit 1. Math 116. Number Systems

CPE100: Digital Logic Design I

Quantitative Aptitude

Continuing discussion of CRC s, especially looking at two-bit errors

Sect Addition, Subtraction, Multiplication, and Division Properties of Equality

CS1800 Discrete Structures Fall 2017 October, CS1800 Discrete Structures Midterm Version A

Math 230 Assembly Language Programming (Computer Organization) Numeric Data Lecture 2

Trinity Web Site Design. Today we will learn about the technology of numbering systems.

Classify, graph, and compare real numbers. Find and estimate square roots Identify and apply properties of real numbers.

UNIT 4 NOTES: PROPERTIES & EXPRESSIONS

Base Number Systems. Honors Precalculus Mr. Velazquez

Grade 7/8 Math Circles Winter March 20/21/22 Types of Numbers

Digital Circuits, Binary Numbering, and Logic Gates Cornerstone Electronics Technology and Robotics II

CIS102 Mathematics for Computing Volume 1

2 ways to write the same number: 6,500: standard form 6.5 x 10 3 : scientific notation

Numbers and Arithmetic


Section 4.7 Scientific Notation

Math From Scratch Lesson 29: Decimal Representation

N= {1,2,3,4,5,6,7,8,9,10,11,...}

UNIVERSITI TENAGA NASIONAL. College of Information Technology

Numbers and Arithmetic

K K.OA.2 1.OA.2 2.OA.1 3.OA.3 4.OA.3 5.NF.2 6.NS.1 7.NS.3 8.EE.8c

Contents. Chapter 2 Digital Circuits Page 1 of 30

ALGEBRA+NUMBER THEORY +COMBINATORICS

CHAPTER 1. REVIEW: NUMBERS

Part I, Number Systems. CS131 Mathematics for Computer Scientists II Note 1 INTEGERS

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

Summer Math Packet for Students Entering 6th Grade. Please have your student complete this packet and return it to school on Tuesday, September 4.

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

Counting, symbols, positions, powers, choice, arithmetic, binary, translation, hex, addresses, and gates.

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

Combinational Logic. By : Ali Mustafa

CSE 20: Discrete Mathematics

Transcription:

CSEN102 Introduction to Computer Science Lecture 7: Representing Information I Prof. Dr. Slim Abdennadher Dr. Mohammed Salem, slim.abdennadher@guc.edu.eg, mohammed.salem@guc.edu.eg German University Cairo, Department of Media Engineering and Technology 24.11.2018-29.11.2018 1 Synopsis 1.1 Synopsis Synopsis What you have learned so far: The idea of algorithms The idea of the meta-solution, history, aspects, definition Notation and principal components of algorithms pseudo-code sequential, conditional, and iterative control-flow Aspects and efficiency of algorithms Analysis of time and space efficiency, depending on the input size Order of magnitude: constant, linear, cubic,... (O(1), O(n), O(n 2 ),... ) In theory, you are now able to write an algorithm for any given computable function. 2 Number systems 2.1 Notation through history 1

And now to something completely different... Positional numbering systems: decimal 1, 10, 100,... are all powers of ten! The meaning of a decimal number: 9 10 0 + 3 10 1 + 1 10 2 + 3 10 3 + 2 10 4 + 6 10 5 + 5 10 6 = 5, 623, 139 This is why it is called decimal The position determines the power of 10, with which the digit at the position has to be multiplied! The first position is with 10 0 = 1, the second with 10 1 = 10, and so on... Finding the perfect base Question How do I choose a good base? Which one is best? 10? 20? 60? Base 10 allows to counting with your fingers Base 20 allows to counting with your fingers and toes Base 60 is a clever mathematical choice because it has many factors (1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60) Another clever mathematical choice would be a prime number as base such as 7 or 11 (opposite idea). 2.2 Computer numbering system The right numbering system Question What base should we chose for a Computer? Computers run with electricity There are two distinct states of most electrical devices (including the transistor is the basis of computers): which off So we should chose a base two system! on 2

3 Binary numbers 3.1 Binary position system Introduction to binary numbers For the binary system we use the powers of 2: Example 1. Observations 2 0 = 1, 2 1 = 2, 2 2 = 4, 2 3 = 8, 2 4 = 16,... 5, 623, 139 10 = 10101011100110101100011 2 We need two different symbols (on off, true false, 1 0, high low, etc.) To write the decimal number 5,623,139 in binary, we need 23 digits. A modern computer usually uses 64 digits, which allows for roughly 18.4 thousand trillion numbers. Terms and names Some terms: Bit : The single binary digit (0 or 1), the smallest unit of information. Byte : Eight bit, which means up to 256 different numbers in positional binary. Word : The base number of digits used by a computer, usually eight byte or 64 bit. 3.2 Using binary Familiar bases Observation It is tedious to switch between binary and decimal! It is much easier with these bases: Octal, or base 8 Hexadecimal, or base 16 (do not mix up with hexagesimal!) Octal, hexadecimal, and binary Imagine a numbering system with base 8 (Octal) Numbers: 0, 1, 2, 3, 4, 5, 6, 7 Example translation: 101 101 001 001 011 011 110 110 2 =5136 8 5 1 3 6 Imagine a numbering system with base 16 (Hexadecimal) Numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Example translation: 10101010 01010101 11101110 2 =A5E 16 A 5 E 3

3.3 First summary Summary We are used to a base 10 positional system Other bases (20, 60) were used through history Generally, a base n system encodes numbers as follows: (x i x i 1... x 1 x 0 ) n = x i n i + x i 1 n i 1 +... + x 1 n 1 + x 0 n 0 We can convert any positional system into any other positional system 1. Write down the digits 2. Multiply each digit by its positional value (the respective power of the base) 3. Add the products Some conversions are very convenient (binary octal, binary hexadecimal,... ) Binary is ideal for computers 3.4 Conversions Two important conversions: Binary to decimal Problem: Convert a binary number into decimal 1. Write down the binary number 2. Write down the positional weight (the factor) 3. Multiply each digit by its weight 4. Do the sum Example 2. Number: 1 0 1 1 0 0 0 1 Positional weight: 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 Factor: 128 64 32 16 8 4 2 1 128 + 0 + 32 + 16 + 0 + 0 + 0 + 1= 177 10 Two important conversions: Decimal to binary Problem: Convert a decimal number into binary Solution by successive division: 1. Divide by the base (i. e., 2) and write down the remainder 2. Repeat division until the quotient equals 0 3. Read the binary number by reading the remainders (bottom-up) 4

Convert 43 into binary Division Quotient Remainder 43/2 21 1 21/2 10 1 10/2 5 0 5/2 2 1 2/2 1 0 1/2 0 1 43 10 = 101011 2 Conversion in general Both algorithms work for any base! Example 3 (Convert (base 60) to decimal:). 46 = 1546 10 Example 4 (Convert 1546 (base 10) to hexadecimal). 1546 10 = 60A 16 Conversion in general Hence you can now convert any base to any other base Problem Convert N 1 with base n to N 2 with base m Solution: 1. Convert N 1 of base n to a decimal number N 2. Convert N to the number N 2 base m Number: Positional weight: 60 1 60 0 Factor: 60 1 1500 + Division Quotient Remainder 1546/16 96 10 96/16 6 0 6/16 0 6 Note: The conversions also work directly as a transition from base n to base m (without the indirection over decimal). It is just unusual. 5