CMPS 10 Introduction to Computer Science Lecture Notes

Similar documents
umber Systems bit nibble byte word binary decimal

Digital Fundamentals

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

DATA REPRESENTATION. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region. Based on CBSE curriculum Class 11. Neha Tyagi, KV 5 Jaipur II Shift

Module 1: Information Representation I -- Number Systems

Lecture (01) Introduction Number Systems and Conversion (1)

CHW 261: Logic Design

Chapter 3 DATA REPRESENTATION

CHAPTER 2 Number Systems

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

MACHINE LEVEL REPRESENTATION OF DATA

BINARY SYSTEM. Binary system is used in digital systems because it is:

Introduction to Numbering Systems

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Objectives. Connecting with Computer Science 2

Beyond Base 10: Non-decimal Based Number Systems

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

CHAPTER 2 (b) : AND CODES

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Digital Logic Lecture 2 Number Systems

Digital Fundamentals

Review of Number Systems

The type of all data used in a C++ program must be specified

Chapter 4: Computer Codes. In this chapter you will learn about:

What Is It? Instruction Register Address Register Data Register

Review of HTML. Ch. 1

Chapter 2 Exercises and Answers

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University

Bits, bytes, binary numbers, and the representation of information

Beyond Base 10: Non-decimal Based Number Systems

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

Digital Systems COE 202. Digital Logic Design. Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

Fundamentals of Programming (C)

Lecture 2: Number Systems

Number Systems. Dr. Tarek A. Tutunji Philadelphia University, Jordan

Octal & Hexadecimal Number Systems. Digital Electronics

Chapter 7. Representing Information Digitally

Chapter 2 Number Systems and Codes Dr. Xu

CS & IT Conversions. Magnitude 10,000 1,

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Introduction to Computer Science (I1100) With 1 coin 2 possibilities: Head / Tail or 0/1

CMPE223/CMSE222 Digital Logic Design. Positional representation

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Switching Circuits and Logic Design Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Level ISA3: Information Representation

Chapter 2 Bits, Data Types, and Operations

Programming Concepts and Skills. ASCII and other codes

Electronic Data and Instructions

Binary Representation. Jerry Cain CS 106AJ October 29, 2018 slides courtesy of Eric Roberts

Logic and Computer Design Fundamentals. Chapter 1 Digital Computers and Information

Binary Systems and Codes

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

CHAPTER 2 Data Representation in Computer Systems

Digital Computers and Machine Representation of Data

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

Final Labs and Tutors

Digital Systems and Binary Numbers

Octal and Hexadecimal Integers

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

TOPICS. Other Number Systems. Other Number Systems 9/9/2017. Octal Hexadecimal Number conversion

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Intermediate Programming & Design (C++) Notation

Chapter 2 Bits, Data Types, and Operations

Bits. Binary Digits. 0 or 1

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Internal Data Representation

CS 101: Computer Programming and Utilization

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

DIGITAL SYSTEM DESIGN

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

Lecture (02) Operations on numbering systems

CC411: Introduction To Microprocessors

CHAPTER 2 Data Representation in Computer Systems

UNIT 7A Data Representation: Numbers and Text. Digital Data

Computer Science 1000: Part #3. Binary Numbers

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Chapter 2 Bits, Data Types, and Operations

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Memory Addressing, Binary, and Hexadecimal Review

T02 Tutorial Slides for Week 2

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

Number Systems Base r

Digital Representation

6. Binary and Hexadecimal

Chapter 2: Number Systems

Number codes nibble byte word double word

Chapter 11 : Computer Science. Information Representation. Class XI ( As per CBSE Board) New Syllabus

Chapter 2. Data Representation in Computer Systems

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Information Science 1

CHAPTER 2 - DIGITAL DATA REPRESENTATION AND NUMBERING SYSTEMS

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

in this web service Cambridge University Press

Lecture C1 Data Representation. Computing and Art : Nature, Power, and Limits CC 3.12: Fall 2007

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

Transcription:

CMPS Introduction to Computer Science Lecture Notes Binary Numbers Until now we have considered the Computing Agent that executes algorithms to be an abstract entity. Now we will be concerned with techniques for designing physical computing machines. Ultimately all data and instructions in modern computing devices are stored as Bits (Binary Digits) i.e. s and s, so we need to discuss the Binary Numbering System. We begin with a more general idea: The Base-b Positional Numbering System. What does 2,526 mean to you? You can read it in words, and you have some sense of how big a number it is, but what does it mean? 2526 = 4 + 2 3 + 5 2 + 2 + 6 This is the Base- Positional Numbering System we are all familiar with. Recall this was introduced to Europe around 2 AD, replacing the earlier Roman numerals and radically improving the efficiency of everyday computations. Given an integer b >, the Base-b Positional Numbering System is obtained by assigning b symbols called digits to the integers:,, 2,..., (b - ). A sequence (or string) of these symbols can then be interpreted as an integer. If the base is b = 5, and the chosen symbols are,,,, and (representing,, 2, 3, and 4 respectively), then the string represents the integer = 3 5 5 + 5 4 + 4 5 3 + 5 2 + 2 5 + 5 = 9,9 Here on earth, we would not use these particular symbols since we already have more familiar ones, namely,, 2, 3, and 4. Since we now wish to express numbers in different basses we will surround a string of digits with square brackets with a subscript to indicate the base. We would thus write [342] 5 = [99]. In general, for any base b, we interpret a string of digits dn d n 2 d 2dd as n n2 2 d d d d d d n n2 2 n n 2 2 b b Note the subscripts on the d s were chosen for convenience to coincide with the powers on the base b. More generally, a fraction is represented by inserting a Base-b point: n 2 k d d d d d d n. 2 k b n 2 k [43.] 5 = 4 5 + 3 5 + 5 - + 5-2 = 2 + 3 + + (/25) = [23.4]

Notice that there is no digit to represent b in the Base-b Positional Numbering System. The string always represents the base of the system. Thus [] 5 = [5] and in general [] b = b. In Computer Science we are most concerned with the following bases. Name Base Digits _ Decimal b =,, 2, 3, 4, 5, 6, 7, 8, 9 Binary b = 2, Octal b = 8,, 2, 3, 4, 5, 6, 7 Hexadecimal b = 6,, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F We will now adopt the practice of omitting the square brackets when referring to base- numerals, and occasionally for other bases when no confusion arises. Why can t we just use to stand for ten in base 6? If we did, what number would the symbol sequence [] 6 stand for? Would it be or would it be 6 + 6 = 6? Counting in binary is like watching the odometer on a car. Decimal Binary 2 3 4 5 6 7 8 9 2 3 4 5 6 3 3 32 33 62 63 64 65 2

Converting from any base into base is easy. Just write down the definition and simplify by doing all your calculations in base, as one would do normally. [] 2 = 5,87 [237] 8 = 59 [A7D] 6 = 4,34 [357] = [? ] 2 List all the powers of 2 up to the first number greater than or equal to 357. k : 2 3 4 5 6 7 8 9 2 k : 2 4 8 6 32 64 28 256 52 Write 357 as a sum of powers of 2. 357 = 256 + = 256 + 64 + 37 = 256 + 64 + 32 + 5 = 256 + 64 + 32 + 4 + = 2 8 + 2 6 + 2 5 + 2 2 + 2 Insert the missing powers of 2. 357 = 2 8 + 2 7 + 2 6 + 2 5 + 2 4 + 2 3 + 2 2 + 2 + 2 Now just read off the binary digits: [357] = [] 2 An alternative approach is to start with 357, compute the quotient and remainder upon division by 2, and repeat the process on the quotient until you reach a quotient of. Remainder 357 Quotient 78 89 44 22 5 2 Now read off the sequence of remainders from bottom to top to get the binary representation of the number:. 3

Exercise Try to write the above procedure in pseudo-code. Expressing a fraction in binary is basically the same process, i.e. first write the number as a sum of powers of two, then read off the binary digits. s 2.75 = 8 + 4 +.5 +.25 = 2 3 + 2 2 + 2 - + 2-2 = [.] 2 5.375 = 8 + 4 + 2 + +.25 +.25 = 2 3 + 2 2 + 2 + 2 + 2-2 + 2-3 = [.] 2 Converting from Binary to Octal is simple since 8 is a power of 2. Just partition your binary number into groups of threes (since 8=2 3 ), adding extra zeros on the left if necessary, then convert each 3-bit binary number into one octal digit. [] 2 = [ ] 2 = [545] 8 Dictionary Octal Binary 2 3 4 5 6 7 Binary to Hexadecimal and back is equally simple since 6 is also a power of 2. This time partition the binary numeral into groups of 4 bits (since 6=2 4 ), again include leading zeros if necessary, then translate each group of 4 bits into one hex digit. [] 2 = [ ] 2 = [65] 6 Dictionary Hexadecimal Binary 2 3 4 5 6 7 8 9 A = B = C = 2 D = 3 E = 4 F = 5 4

Reversing this process is also very simple. [332] 8 = [ ] 2 = [2DA] 6 = [ ] 2 = Doing arithmetic in other bases is little different than doing it in base ten. Just carry when a column sum is greater than the base. Binary + Octal 733 + 572 525 Hexadecimal DB + 7A 355 Observe that these three examples are actually one and the same. In decimal they would read 475 + 378 853 In modern computers, all data is stored in binary form, whether it be numeric data or any other type of information. The fundamental unit of memory is a single cell. In almost every modern architecture a cell consists of 8 bits, also known as byte. byte = 8 bits How many different bit patterns can be represented in byte? More generally, how many different bit patterns of length n are there, for any n? There are 2 choices ( or ) for the first bit, 2 choices for the second bit, 2 for the third,..., and finally 2 choices for the n th bit. Thus there are 2 2 2 2 = 2 n choices for the entire bit string. Thus # bit strings of length n = 2 n 5

Since a single memory cell holds byte = 8 bits, it can store 2 8 = 256 different bit patterns. If these bit strings represent integers, then the range is = to = 255. To store integers outside this range requires more than one cell. We ve discussed how to encode numeric data using bits, but how can we encode other types of information, such as text? There are a number of different Character Encodings in use. ASCII (American Standard Code for Information Interchange) uses byte (8 bits) to represent a single character. The codes -3 represent control characters, codes 32-27 are the printable characters, and 28-255 are the so-called extended ASCII character set, which includes special symbols. See http://www.ascii-code.com/ for a complete table. Hello World! would be represented (without quotes ) as Binary Hex 48 65 6C 6C 6F 2 57 6F 72 6C 64 2 Unicode uses 2 bytes (6 bits) to store a single character. The number of characters that can be represented is therefore 2 6 = 65,536. This is many more than are available on a typical keyboard. We need so many to represent characters in all the world s alphabets. The Unicode representation of Latin letters and English language keyboard symbols are just the ASCII codes pre-pended with 8 s, so for instance H in Unicode is (=48 in Hex). Go to http://unicode.org/charts/ to see the complete UNICODE character set. 6