Fundamentals of Programming (C)

Similar documents
Fundamentals of Programming

Data Representation and Binary Arithmetic. Lecture 2

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Number System (Different Ways To Say How Many) Fall 2016

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Number System

Chapter 2 Bits, Data Types, and Operations

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Chapter 2 Bits, Data Types, and Operations

Number Systems Base r

Positional Number System

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

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

Chapter 2 Bits, Data Types, and Operations

Oberon Data Types. Matteo Corti. December 5, 2001

3.1. Unit 3. Binary Representation

Chapter 3. Information Representation

Number Representations

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Chapter 2 Bits, Data Types, and Operations

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

The Binary Number System

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Under the Hood: Data Representation. Computer Science 104 Lecture 2

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

Lecture (09) x86 programming 8

ASSIGNMENT 5 TIPS AND TRICKS

Fundamental Data Types

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

EE 109 Unit 2. Binary Representation Systems

Chapter 8. Characters and Strings

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

UNIT 2 NUMBER SYSTEM AND PROGRAMMING LANGUAGES

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

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

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Hardware. ( Not so hard really )

Connecting UniOP to Datalogic Barcode Readers

Do not start the test until instructed to do so!

Variables and data types

FA269 - DIGITAL MEDIA AND CULTURE

Electronic Data and Instructions

Do not start the test until instructed to do so!

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

Source coding and compression

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

User s Manual. Xi3000 Scanner. Table of Contents

Imperial College London Department of Computing

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

S-Series Sensor ASCII Protocol v8.1.0

Characters Lesson Outline

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

Digital Representation

Digital Systems and Binary Numbers

CS & IT Conversions. Magnitude 10,000 1,

CSC 8400: Computer Systems. Represen3ng and Manipula3ng Informa3on. Background: Number Systems

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

ASCII Code - The extended ASCII table

Xi2000-BT Series Configuration Guide

4/14/2015. Architecture of the World Wide Web. During this session we will discuss: Structure of the World Wide Web

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

Number representations

Do not start the test until instructed to do so!

CPSC 301: Computing in the Life Sciences Lecture Notes 16: Data Representation

Chapter 7. Binary, octal and hexadecimal numbers

FD-011WU. 2D Barcode Reader User Guide V1.6CC

Chapter 1. Hardware. Introduction to Computers and Programming. Chapter 1.2

CSE 30 Fall 2013 Final Exam

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

Serial I/O. 4: Serial I/O. CET360 Microprocessor Engineering. J. Sumey

8.2 User Defined Protocol Communication

MOBILE THERMAL PRINTER

2D BARCODE SCANNER CA-SC-20200B

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

Lecture 2: Number Systems

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

Simple Data Types in C. Alan L. Cox

marson MT8200S 2D Handheld Scanner User Manual V / 6 / 25 - I -

Digital Fundamentals

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

CSE 30 Winter 2014 Final Exam

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

Transcription:

Borrowed from lecturer notes by Omid Jafarinezhad Fundamentals of Programming (C) Group 8 Lecturer: Vahid Khodabakhshi Lecture Number Systems Department of Computer Engineering

Outline Numeral Systems Computer Data Storage Units Numeral Systems Conversion Calculations in Number Systems Signed Integer Representation Fractional and Real Numbers ASCII Codes Department of Computer Engineering /

Numeral Systems Decimal number system (base ) Binary number system (base ) Computers are built using digital circuits Inputs and outputs can have only two values: and or True (high voltage) or false (low voltage) Writing out a binary number such as is tedious, and prone to errors Octal and hex are a convenient way to represent binary numbers, as used by computers Octal number system (base 8) Hexadecimal number system (base 6) Department of Computer Engineering /

Numeral Systems Decimal Binary Octal Hexadecimal Base B : digit B - -------------------------------------------- Base : digit 9 ( -) Base : digit (-) Base 8 : digit (8 -) Base 6 : digit 5 (6 -) 5 6 5 6 5 6 8 8 9 9 A (decimal value of ) B (decimal value of ) C (decimal value of ) D (decimal value of ) E (decimal value of ) F (decimal value of 5) Department of Computer Engineering /

Computer Data Storage Units Bit OR Each bit can only have a binary digit value: or basic capacity of information in computer A single bit must represent one of two states: = How many state can encode by N bit? Department of Computer Engineering 5/

Department of Computer Engineering 6/ Binary Encoding 5 6 5 6 8 9 5

Department of Computer Engineering / Computer Data Storage Units Byte: A sequence of eight bits or binary digits 8 = 56 (..55) smallest addressable memory unit 5 6 Bit Order One Bit Memory Address

Computer Data Storage Units Kilo byte: b = b ~ b = x = KB = 8 b 6 = 6 x = 6 KB = 6556 b Mega byte: b = b = x = M Giga byte:. Department of Computer Engineering 8/

Numeral Systems Conversion Convert from Base-B to Base-: (A) B = (?) () = () (.) = (?) (56) 8 = (?) (b) 6 = (?) Convert from Base- to Base-B: (N) = (?) B () = (?) (9) = (?) 8 (96) = (?) 6 Department of Computer Engineering 9/

Convert from Base-B to Base-. Define bit order.. 6 5 - - -.... Example : Base- to Base- 6 5 - - - -. Department of Computer Engineering /

Convert from Base-B to Base-. Calculate Position Weight B bit order Decimal Point - - s s s /s /s 9 8. 5 6 Example : Base- to Base- Position Weight B = 6 5 - - - - 6 5 - - - -. Department of Computer Engineering /

Convert from Base-B to Base-. Multiplies the value of each digit by the value of its position weight 8 6 6 8.5.5.5.65 6 5 - - - -. 8 6 6 8.5.5.5.65 8 6 8..5.65 Department of Computer Engineering /

Convert from Base-B to Base-. Adds the results of each section 8 6 6 8.5.5.5.65 6 5 - - - -. 8 6 6 8.5.5.5.65 8 6 8..5.65.5 +.5 Department of Computer Engineering /

Convert from Base-B to Base- Examples: (a n- a n- a. a - a -m ) B = (N) N = (a n- B n- ) + (a n- B n- ) + + (a B ) + (a - B - ) + + (a -m B m ) () = ( ) + ( ) + ( ) + ( ) = () (56) 8 = ( 8 ) + ( 8 ) + (58 ) + (68 ) = (9) (b) 6 = ( 6 ) + (6 ) + (6 ) = (96) (E6.A) 6 = ( 6 ) + (6 ) + (66 ) + ( ( / 6)) + ( ( / (6 6))) = (?) 6-6 - Department of Computer Engineering /

Convert from Base- to Base-B (N) = ( a n- a n- a. a - a -m ) B Integer part Fraction part. Convert integer part to Base-B Consecutive divisions. Convert fraction part to Base-B Consecutive multiplication 5.5 5.5 Department of Computer Engineering 5/

Convert Integer Part to Base-B Repeat until the quotient reaches Write the reminders in the reverse order Last to first Examples: ( 5 ) = () 5 Department of Computer Engineering 6/ 6 6

Convert Integer Part to Base-B Examples: 9 88 6 8 6 56 5 8 8 96 9 6 59 8 6 6 (9) = (56) 8 (96) = (B) 6 Department of Computer Engineering /

Convert Fraction Part to Base-B Do While multiply fraction part by B (the result) drop the integer part of the result (new fraction) (result = ) OR (reach to specific precision) the integral parts from top to bottom are arranged from left to right after the decimal point Department of Computer Engineering 8/

Convert Fraction Part to Base-B Example:.5 =.5.5 =.5 (.5) = (.).5 =... =. Department of Computer Engineering 9/

Convert Fraction Part to Base-B Example:.6 =.. =. (.6) = (.). =.8.8 =.6.6 = Department of Computer Engineering /

Conversion binary and octal Binary to Octal = 8 Octal 5 6 Binary Each digit in octal format: digits in binary format If the number of digits is not dividable by, add additional zeros: a a a a. a - a - = = =. =. (.) = (.) = (.6) 8 6 Department of Computer Engineering /

Conversion binary and octal Octal to Binary Substitute each digit with binary digits (5) 8 = () () 8 = () (5) 8 = ( ) (.6) 8 = (. ) Department of Computer Engineering /

Conversion binary and Hexadecimal Binary to Hexadecimal = 6 Each digit in octal format: digits in binary format If the number of digits is not dividable by, add additional zeros: a a a a. a - a - (.) 6 = (.) 6 = (D.6) D 6 Department of Computer Engineering /

Conversion binary and Hexadecimal Hexadecimal to Binary Substitute each digit with binary digits (F5.) 6 = (. ). Department of Computer Engineering /

Conversion Octal binary Hexadecimal (5) 8 = (E5) 6 (5) 8 = () = () = (E5) 6 5 E 5 (FA5) 6 = () = () = (65) 8 = (65) 8 Department of Computer Engineering 5/

Calculations in Numeral Systems Addition Binary ( + ) () = () carried digits () () (6) + + + Department of Computer Engineering 6/

Calculations in Numeral Systems Addition Hexadecimal Octal 5 6 8 B D A 8 B D A B 5 E (8 + D ) 6 (8 + ) = () = (5) 6 ( + 6 ) () = () 8 6 Department of Computer Engineering /

Calculations in Numeral Systems Subtraction Binary Borrowed digit () = () Borrowed digits () () (6) Department of Computer Engineering 8/

Calculations in Numeral Systems Subtraction Hexadecimal 6 + = 6 6 + = 9 5 + 6 = 5 9 6 Octal C F 6+ 8 = 6 Department of Computer Engineering 9/

Signed Integer Representation Negative numbers must be encode in binary number systems Well-known methods Sign-magnitude One s Complement Two s Complement Which one is better? Calculation speed Complexity of the computation circuit Department of Computer Engineering /

Sign-magnitude One sign bit + magnitude bits Positive: s = Negative: s= Range = {(-).. (+) } Two ways to represent zero: (+) ( ) Examples: (+ ) = (- ) = s Sign 6 5 Magnitude How many positive and negative integers can be represented using N bits? Positive: N- - Negative: N- - Department of Computer Engineering /

Two s Complement Negative numbers:. Invert all the bits through the number ~() = ~() =. Add one Example: + = - =? ~() + Only one zero () Range = {.. 8} - - Negative two's complement () -() = - ~() + Department of Computer Engineering /

ASCII Codes American Standard Code for Information Interchange First decision: bits for representation Final decision: 8 bits for representation 56 characters ASCII ( P ) = (5) 6 ASCII ( = ) = (D) 6 row number column number Hexadecimal 5 6 NUL DLE @ P ` p SOH DC! A Q a q STX DC " B R b r ETX DC # C S c s EOT DC $ D T d t 5 ENQ NAK % 5 E U e u 6 ACK SYN & 6 F V f v BEL ETB ' G W g w 8 BS CAN ) 8 H X h x 9 TAB EM ( 9 I Y i y A LF SUB : J Z j z B VT ESC + ; K ] k } C FF FS, > L \ l D CR GS - = M [ m { E SO RS. < N ^ n ~ F SI US /? O _ o Department of Computer Engineering /

Summary Numeral Systems Decimal, Binary, Octal, Hexadecimal Computer Data Storage Units Bit, Byte, Kilo byte, Giga byte, Numeral Systems Conversion Convert between different bases Calculations in Number Systems Addition and subtraction Signed Integer Representation Sing-magnitude: one sign bit + magnitude bits Two s complement : (-N) = ~(N) + Fractional and Real Numbers ASCII Codes Department of Computer Engineering /