CS101 Lecture 12: Number Systems and Binary Numbers

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

Chapter 2. Binary Values and Number Systems

Useful Number Systems

CSI 333 Lecture 1 Number Systems

Base Conversion written by Cathy Saxton

Section 1.4 Place Value Systems of Numeration in Other Bases

Lecture 11: Number Systems

Computer Science 281 Binary and Hexadecimal Review

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

=

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

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

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

Binary Numbers. Binary Octal Hexadecimal

Binary Representation

Positional Numbering System

NUMBER SYSTEMS. William Stallings

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

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Lecture 2. Binary and Hexadecimal Numbers

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

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

Binary, Hexadecimal, Octal, and BCD Numbers

CS201: Architecture and Assembly Language

CPEN Digital Logic Design Binary Systems

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

COMPSCI 210. Binary Fractions. Agenda & Reading

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

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

Chapter 4: Computer Codes

Binary Adders: Half Adders and Full Adders

Number Systems and Radix Conversion

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

NUMBER SYSTEMS. 1.1 Introduction

Number Representation

Decimal to Binary Conversion

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

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

3. Convert a number from one number system to another

Data Representation. What is a number? Decimal Representation. Interpreting bits to give them meaning. Part 1: Numbers. six seis

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

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

Unsigned Conversions from Decimal or to Decimal and other Number Systems

HOMEWORK # 2 SOLUTIO

Zero: If P is a polynomial and if c is a number such that P (c) = 0 then c is a zero of P.

Systems I: Computer Organization and Architecture

THE BINARY NUMBER SYSTEM

Numbering Systems. InThisAppendix...

CS321. Introduction to Numerical Methods

Memory is implemented as an array of electronic switches

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

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

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

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

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

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

1. How many unique network IDs are there in class A addresses? # of unique hosts?

A Step towards an Easy Interconversion of Various Number Systems

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

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

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: b + 90c = c + 10b

Chapter 1: Digital Systems and Binary Numbers

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

Chapter 5 Instructor's Manual

The Hexadecimal Number System and Memory Addressing

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

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

Counting in base 10, 2 and 16

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

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

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

Prerequisite knowledge Students should have a good understanding of how our decimal number system works as well as understand place value.

Number Systems. Introduction / Number Systems

Preliminary Mathematics

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

2.3 IPv4 Address Subnetting Part 2

Cyber Security Workshop Encryption Reference Manual

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

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

Activity 6.7.4: IPv4 Address Subnetting Part 2

Upon completion of unit 1.1, students will be able to

Solution for Homework 2

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

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Solution Guide Chapter 14 Mixing Fractions, Decimals, and Percents Together

Internet Protocol Address

TCP/IP Cheat Sheet. A Free Study Guide by Boson Software, LLC

BCD (ASCII) Arithmetic. Where and Why is BCD used? Packed BCD, ASCII, Unpacked BCD. BCD Adjustment Instructions AAA. Example

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

MULTIPLICATION AND DIVISION OF REAL NUMBERS In this section we will complete the study of the four basic operations with real numbers.

26 Integers: Multiplication, Division, and Order

Expert Reference Series of White Papers. Simple Tricks To Ace the Subnetting Portion of Any Certification Exam COURSES.

Classless Subnetting Explained

10CS35: Data Structures Using C

Data Storage. 1s and 0s

Supplemental Worksheet Problems To Accompany: The Pre-Algebra Tutor: Volume 1 Section 1 Real Numbers

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Transcription:

CS101 Lecture 12: Number Systems and Binary Numbers John Magee 15 July 2013 Some material copyright Jones and Bartlett 1 2 1

3!!! MATH WARNING!!! TODAY S LECTURE CONTAINS TRACE AMOUNTS OF ARITHMETIC AND ALGEBRA PLEASE BE ADVISED THAT CALCULTORS WILL BE ALLOWED ON THE QUIZ (and that you probably won t need them) 4 2

Overview/Questions What gives a number its value? What is a number system? I ve heard that computers use binary numbers. What s a binary number? What kind of numbers do computers store and manipulate? 5 Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers A value less than 0, with a sign Examples: -24, -1, -45645, -32 6 2 3

Numbers Integers A natural number, a negative number, zero Examples: 249, 0, -45645, -32 Rational Numbers An integer or the quotient of two integers Examples: -249, -1, 0, 3/7, -2/5 7 3 Numbering Systems A numbering system assigns meaning to the position of the numeric symbols. For example, consider this set of symbols: 642 What number is it? Why? 8 4 4

Numbering Systems It depends on the numbering system. 642 is 600 + 40 + 2 in BASE 10 The base of a number determines the number of digits (e.g. symbols) and the value of digit positions 9 5 Positional Notation Continuing with our example 642 in base 10 positional notation is: 6 x 10 2 = 6 x 100 = 600 + 4 x 10 1 = 4 x 10 = 40 + 2 x 10º = 2 x 1 = 2 = 642 in base 10 This number is in base 10 The power indicates the position of the number 10 6 5

Positional Notation 642 is 6 3 * 10 2 + 4 2 * 10 1 + 2 1 * 100 As a general form: B is the base of the number d n * B n-1 + d n-1 * B n-2 +... + d 1 * B 0 n is the number of digits in the number d is the digit in the i th position in the number 11 7 What Would Pooh Do? 12 6

Binary Numbers Digital computers are made up of electronic circuits, which have exactly 2 states: on and off. Computers use a numbering system which has exactly 2 symbols, representing on and off. 13 9 Binary Numbers Decimal is base 10 and has 10 digits: 0,1,2,3,4,5,6,7,8,9 Binary is base 2 and has 2, so we use only 2 symbols: 0,1 For a given base, valid numbers will only contain the digits in that base, which range from 0 up to (but not including) the base. 14 9 7

Counting Let s remember Kindergarten 15 Binary Numbers and Computers A binary digit or bit can take on only these two values. Low Voltage = 0 High Voltage = 1 all bits have 0 or 1 Binary numbers are built by concatenating a string of bits together. Example: 10101010 16 22 8

Positional Notation: Binary Numbers Recall this general form: d n * B n-1 + d n-1 * B n-2 +... + d 1 * B 0 The same can be applied to base-2 numbers: 1011(binary) =1 * 2 3 (1 * 8) + 0 * 2 2 (0 * 4) + 1 * 2 1 (1 * 2) + 1 * 2 0 (1 * 1) 1011(binary) =8 + 0 + 2 + 1 = 11(decimal) 17 Converting Binary to Decimal What is the decimal equivalent of the binary number 01101110? (you try it! Work left-to-right) 18 13 9

Converting Binary to Decimal What is the decimal equivalent of the binary number 01101110? 0 x 2 7 = 0 x 128 = 0 + 1 x 2 6 = 1 x 64 = 64 + 1 x 2 5 = 1 x 32 = 32 + 0 x 2 4 = 0 x 16 = 0 + 1 x 2 3 = 1 x 8 = 8 + 1 x 2 2 = 1 x 4 = 4 + 1 x 2 1 = 1 x 2 = 2 + 0 x 2º = 0 x 1 = 0 = 110 (decimal) 19 13 Converting Binary to Decimal Try another one. What is the decimal equivalent of the binary number 10101010? (you try it! Work left-to-right) 20 13 10

Converting Binary to Decimal Try another one. What is the decimal equivalent of the binary number 10101010? 1 x 2 7 = 1 x 128 = 128 + 0 x 2 6 = 0 x 64 = 0 + 1 x 2 5 = 1 x 32 = 32 + 0 x 2 4 = 0 x 16 = 0 + 1 x 2 3 = 1 x 8 = 8 + 0 x 2 2 = 0 x 4 = 0 + 1 x 2 1 = 1 x 2 = 2 + 0 x 2º = 0 x 1 = 0 = 170 (decimal) 21 13 Converting from Decimal to Other Bases Algorithm (process) for converting number in base 10 to other bases While (the quotient is not zero) Divide the decimal number by the new base* Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient * Using whole number (integer) division only. Example: 3 / 2 gives us a quotient of 1 and a remainder 1 22 19 11

Converting Decimal to Binary What is the binary equivalent of the decimal number 103? 103 / 2 = 51, remainder 1 rightmost bit 51 / 2 = 25, remainder 1 25 / 2 = 12, remainder 1 12 / 2 = 6, remainder 0 6 / 2 = 3, remainder 0 3 / 2 = 1, remainder 1 1 / 2 = 0, remainder 1 leftmost bit 103 (decimal) = 1 1 0 0 1 1 1 (binary) 23 Converting Decimal to Binary Now you try one. What is the binary equivalent of the decimal number 201? Recall the algorithm: While (the quotient is not zero) Divide the decimal number by the new base* Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient 24 12

Converting Decimal to Binary What is the binary equivalent of the decimal number 201? 201 / 2 = 100, remainder 1 rightmost bit 100 / 2 = 50, remainder 0 50 / 2 = 25, remainder 0 25 / 2 = 12, remainder 1 12 / 2 = 6, remainder 0 6 / 2 = 3, remainder 0 3 / 2 = 1, remainder 1 1 / 2 = 0, remainder 1 leftmost bit 201 (decimal) = 1 1 0 0 1 0 0 1 (binary) 25 Binary and Computers Byte 8 bits a common unit of computer memory. Word A computer word is a group of bits which are passed around together during computation. The word length of the computer s processor is how many bits are grouped together. 8-bit machine (e.g. Nintendo Gameboy, 1989) 16-bit machine (e.g. Sega Genesis, 1989) 32-bit machines (e.g. Sony PlayStation, 1994) 64-bit machines (e.g. Nintendo 64, 1996) 26 23 13

Common Number Systems Binary base 2, has 2 symbols: 0,1 Octal base 8, has 8 symbols: 0,1,2,3,4,5,6,7 Decimal base 10, has 10 symbols: 0,1,2,3,4,5,6,7,8,9 Hexadecimal - base 16 has 16 digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F 27 Why Hexadecimal? Base 16 is a multiple of Base 2: 16 = 2 4 Each four bits map to a hex digit. Converts easily to and from binary 28 14

Binary, Hexadecimal, Decimal Each four bits map to a hex digit. Hexadecimal prefix 0x???? No inherent value, just means treat as a hex number 0x94D3 29 Hexadecimal to Decimal Convert each hex digit into 4 bits. Convert binary to decimal. Example: 0x94D3 = 1001 0100 1101 0011 = 2 15 + 2 12 + 2 10 + 2 7 + 2 6 + 2 4 + 2 1 + 2 0 = 32768 + 4096 + 1024 + 128 + 64 + 16 + 2 + 1 = 38099 (decimal) 30 15

Try some! Conversions Between Number Systems http://www.mathsisfun.com/binary-decimalhexadecimal-converter.html My phone number: 0x16FF8BA69 (or: 101101111111110001011101001101001) 31 Take-Away Points Symbols represent values Number systems Binary Hexadecimal When do computers use decimal, octal, and hexadecimal numbers? 32 16