Introduction to Computer Systems and Software Lecture 2 of 2 Simon Coupland

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

Lecture - 2 Number systems and computer data formats
Chapter 2 : Number System
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Data Representation Computer Organization &
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Data Representation COE 205
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.

CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
Computers Organization & Assembly Language
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
IT253: Computer Organization
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
The Teacher CP4 Binary and all that… CP4 Revision.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
The Teacher CP4 Binary and all that… CP4 Revision.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CS 160 Lecture 4 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
NUMBER SYSTEMS AND CODES. CS Digital LogicNumber Systems and Codes2 Outline Number systems –Number notations –Arithmetic –Base conversions –Signed.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Number Representation and Arithmetic Circuits
Lecture 2 Number Representation, Overflow and Logic Topics Adders Math Behind Excess-3 Overflow Unsigned, signed-magnitude Two’s Complement Gray Code Boolean.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Computer Representation of Information
CS2100 Computer Organisation
Data Representation COE 308 Computer Architecture
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Number Representation
CS1010 Programming Methodology
Data Representation COE 301 Computer Organization
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Data Representation ICS 233
ECE 331 – Digital System Design
Computer Architecture CST 250
Data Representation COE 308 Computer Architecture
Chapter 1 Introduction.
Presentation transcript:

Introduction to Computer Systems and Software Lecture 2 of 2 Simon Coupland

Representation of Data Within the Computer Contents:  Decimal and Binary Integer Numbers  Binary Addition  Signed Binary Numbers  Overflow  Hexadecimal Numbers  Number Conversion  Real Numbers  Character Encoding

Introduction A few terms:  A bit – a single Binary digIT, 0 or 1  A byte – eight bits  A word – one or more bytes  Integer – whole number  Real number – a number with decimal points  Binary – Base 2 numbers  Octal – Base 8 numbers  Decimal – Base 10 numbers (everyday numbers)  Hexadecimal – Base 16 numbers

Decimal and Binary Numbers We all use decimal numbers Base 10 numbers Example: 124 Digit Digit Value Digit Value10M1M100k10k1k Example

Decimal and Binary Numbers Computers use binary numbers Base 2 numbers: Example: 124 Bit Bit Value Example

Decimal and Binary Numbers More binary numbers: = = = = = = 0

Binary Addition When adding binary numbers we use binary logic Binary Addition Truth Table 1: ABA + BCarry

Binary Addition Binary Addition Truth Table 2: ABCarry (in)A + BCarry (out)

Binary Addition Binary Addition Example: =

Binary Addition Binary Addition Example: = 0 1

Binary Addition Binary Addition Example: = 10

Binary Addition Binary Addition Example: = 110

Binary Addition Binary Addition Example: = 1110

Binary Addition Binary Addition Example: =

Binary Addition Binary Addition Example: =

Binary Addition Binary Addition Example: =

Binary Addition Binary Addition Example: =

Binary Addition Binary Addition Q1: =

Binary Addition Binary Addition Q1: =

Binary Addition Binary Addition Q2: =

Binary Addition Binary Addition Q2: =

Binary Addition Binary Addition Q3: =

Binary Addition Binary Addition Q3: =

Negative Binary Numbers Sign-true Magnitude Left most bit holds sign Example: -10 Bit Bit Valuesign Bit Value+/ Example

Negative Binary Numbers Ones complement All 1’s and 0’s are switched When negative, result = value Example: -10 Bit Bit Value Example

Negative Binary Numbers Twos complement Left most bit holds sign When negative, result = result Example: -10 Bit Bit ValueSign Bit Value+/ Example

Negative Binary Numbers Conversion to Twos complement  Ones complement the byte/word  Add 1 Example: Ones complement =

Why Use Twos Complement? Because addition rules still work: = = -98

Overflow Overflow is when the number of bits is too small to store the result of an arithmetic operation Example (twos complement) : = = -45

Overflow Overflow can be easily detected for signed binary numbers Errors can then be corrected Adding two positive numbers should give a positive result Adding two negative numbers should give a negative result Adding a positive and negative number together can never result in overflow. Why?

Hexadecimal Numbers Writing code with long binary numbers would be cumbersome and error prone A hexadecimal digit can take 16 values (0-F) One hex digit can represent a four bit word Examples: DecimalHexadecimalBinary A A

Number Conversion Binary to Hexadecimal:  From the least significant (rightmost) bit split the binary number into groups of four bits.  Each 4 bits has a hexadecimal equivalent  Example: E

Number Conversion Hexadecimal to Binary:  Convert each hexadecimal digit into its 4 bit binary equivalent  Join the all 4 bit words together  Example: A42F

Number Conversion Question Hexadecimal to Binary:  Convert D36B into binary

Number Conversion Question Hexadecimal to Binary:  Convert D36B into binary D 3 6 B

Number Conversion Question Binary to Hexadecimal:  Convert into hexadecimal

Number Conversion Question Binary to Hexadecimal:  Convert into hexadecimal A 8 A

Number Conversion Decimal to Binary  Use the following algorithm, begin with LSB int dec_value = some_number; int next_bit; while(dec_value > 0) { next_bit = dec_value % 2; dec_value = dec_value / 2; }

Number Conversion Decimal to Binary Convert 42 to binary: dec_value/2%2Result

Number Conversion Question Convert 39 to binary:

Number Conversion Question Convert 39 to binary: dec_value/2%2Result

Number Conversion Binary to Decimal  Use the following algorithm, begin with MSB int dec_value = 0; int bit_value; int bit_index = MSB_index; while(bit_index >= 0) { bit_value = word[bit_index]; dec_value = dec_value * 2 + bit_value; bit_index--; }

Number Conversion Binary to Decimal  Convert to decimal: bit_indexbit_valuedec_value

Number Conversion Binary to Decimal  Question, convert to decimal:

Number Conversion Binary to Decimal  Question, convert to decimal: bit_indexbit_valuedec_value

Number Conversion Decimal to Hexadecimal  Use the following algorithm, begin with LSB int dec_value = some_number; char hex_digit; while(dec_value > 0) { hex_digit = to_hex(dec_value % 16); dec_value = dec_value / 16; }

Number Conversion Decimal to Hexadecimal  Convert 1863 to hexadecimal dec_valuedec_value / 16dec_value % 16hex_digit

Number Conversion Decimal to Hexadecimal  Question, convert 1437 to hexadecimal

Number Conversion Decimal to Hexadecimal  Question, convert 1437 to hexadecimal dec_valuedec_value / 16dec_value % 16hex_digit D

Number Conversion Hexadecimal to Decimal  Use the following algorithm, begin with MSB int dec_value = 0; char digit_value; while(!word.off) { digit_value = to_dec(hex_digit); dec_value = dec_value * 16 + digit_value; }

Number Conversion Hexadecimal to Decimal  Convert F2AC to decimal Indexhex_valuedec_valueresult 3F A C

Number Conversion Hexadecimal to Decimal  Convert E59A to decimal

Number Conversion Hexadecimal to Decimal  Convert E59A to decimal Indexhex_valuedec_valueresult 3E A

Real Numbers A number n is a real number if n % 1 != 0 Take a lot of processing power/time Often math co-processors are used to perform arithmetic on these numbers

Fixed Point Real Numbers Similar to integer representation 8 bit example: Bit value-/ value-/

Fixed Point Real Numbers Maximum number is small Accuracy is limited Not used because of these reasons

Floating Point Real Numbers Floating point numbers are held in two parts  Mantissa  Exponent In   10 4 The mantissa is The exponent is 4

Floating Point Real Numbers Example (not IEEE float): mantissaexponent Mantissa = 809 Exponent = 

Character Encoding ASCII EBCDIC UNICODE ISO

Character Encoding ASCII  American Standard Code for Information Interchange  Characters are represented by integers  Table in your notes A = 65 B = 66 a = 96 z = = 64

Character Encoding ASCII  Special functions characters are also encoded  Examples: Carriage return = 13 Escape = 27 Space = 32

Recap Binary numbers can be signed of unsigned Twos complement gives simple addition Overflow - when the result of a arithmetic operation is too large to be represented Hexadecimal numbers – base 16 Real numbers use floating point Characters are represented as intergers