Experimental Methods I

Similar documents
The type of all data used in a C (or C++) program must be specified

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

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

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Electronic Data and Instructions

Binary. Hexadecimal BINARY CODED DECIMAL

MACHINE LEVEL REPRESENTATION OF DATA

Module 2: Computer Arithmetic

Digital Fundamentals

Chapter 1. Data Storage Pearson Addison-Wesley. All rights reserved

Dec Hex Bin ORG ; ZERO. Introduction To Computing

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

REPRESENTING INFORMATION:

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Intermediate Programming & Design (C++) Notation

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Introduction to Computers and Programming. Numeric Values

Final Labs and Tutors

Computer Organization and Levels of Abstraction

The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Purpose of Chapter. External Representation of Information.

CHW 261: Logic Design

Computer Organization and Levels of Abstraction

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Analogue vs. Discrete data

Binary Adders: Half Adders and Full Adders

ECE 30 Introduction to Computer Engineering

M1 Computers and Data

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Invitation to Computer Science, C++ Version, Third Edition

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Objectives. Connecting with Computer Science 2

Digital Computers and Machine Representation of Data

Data Storage. Slides derived from those available on the web site of the book: Computer Science: An Overview, 11 th Edition, by J.

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

CC411: Introduction To Microprocessors

Bits and Bit Patterns

Logic, Words, and Integers

LECTURE 4. Logic Design

Review Topics. Midterm Exam Review Slides

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

Basic data types. Building blocks of computation

Review Topics. Midterm Exam Review Slides

Binary Codes. Dr. Mudathir A. Fagiri

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Jianhui Zhang, Ph.D., Associate Prof. College of Computer Science and Technology, Hangzhou Dianzi Univ.

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

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

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

Microcomputers. Outline. Number Systems and Digital Logic Review

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

Introduction to Computer Science. Homework 1

Module 1: Information Representation I -- Number Systems

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Bits, Words, and Integers

Chapter 4. Operations on Data

Digital Logic Design Exercises. Assignment 1

Using sticks to count was a great idea for its time. And using symbols instead of real sticks was much better.

Chapter 3 DATA REPRESENTATION

计算机信息表达. Information Representation 刘志磊天津大学智能与计算学部

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

Birkbeck (University of London) Department of Computer Science and Information Systems. Introduction to Computer Systems (BUCI008H4)

Introduction to the Use of Computers

Topic Notes: Bits and Bytes and Numbers

1. Which of the following Boolean operations produces the output 1 for the fewest number of input patterns?

COMP Overview of Tutorial #2

Number Systems. Both numbers are positive

Chapter 4: Data Representations

COMP2611: Computer Organization. Data Representation

Fundamentals of Programming

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

Topic Notes: Bits and Bytes and Numbers

EE292: Fundamentals of ECE

that system. weighted value associated with it. numbers. a number. the absence of a signal. MECH 1500 Quiz 2 Review Name: Class: Date:

Chapter 2. Data Representation in Computer Systems

Outline. policies. with some potential answers... MCS 260 Lecture 19 Introduction to Computer Science Jan Verschelde, 24 February 2016

Computer Organisation CS303

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

CS 101: Computer Programming and Utilization

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Number System. Introduction. Decimal Numbers

Lecture 10: Floating Point, Digital Design

Fundamentals of Programming (C)

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.

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Chapter 2 Bits, Data Types, and Operations

History of Computing. Ahmed Sallam 11/28/2014 1

UNCA CSCI 255 Exam 1 Spring February, This is a closed book and closed notes exam. It is to be turned in by 1:45 PM.

Digital Fundamentals

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

THE LOGIC OF COMPOUND STATEMENTS

CDS Computing for Scientists. Midterm Exam Review. Midterm Exam on October 22, 2013

OCR H446 A-Level Computer Science

National 5 Computing Science Software Design & Development

Birkbeck (University of London) Department of Computer Science and Information Systems. Introduction to Computer Systems (BUCI008H4)

DIGITAL SYSTEM DESIGN

Transcription:

Experimental Methods I Computing: Data types and binary representation M.P. Vaughan Learning objectives Understanding data types for digital computers binary representation of different data types: Integers (positive and negative) Real numbers Boolean variables Text characters How simple addition may be implemented in a digital computer 1

Data types A data type defines a particular kind of data Formally What kind of data (integer, real, character etc.) The allowed values Practically How the data is represented in terms of bits Bits A bit is a unit of data that (in binary digital computer) can either be 1 or 0 The corresponds to high or low voltage in a digital circuit E.G. the inputs and outputs to logic circuits (NAND, NOR etc.) 2

Bytes 1 byte is composed of 8 bits Since each bit can be either 1 or 0, the number of different values a byte can represent is b b b b b b b b More bytes 1 kilobyte (kb) = 1024 bytes Why 1024 and not 1000? 1024 = 2 10, but 1000 is not a power of 2 1 megabyte (MB) = 2 20 bytes 2 20 = 1024 x 1024 = 1,048,576 1 gigabyte (GB) = 2 30 bytes 1 terabyte (TB) = 2 40 bytes 3

Number bases In base N there are N digits. Each digit in a number represents a multiply of a power of N D 2 D 1 D 0 D -1 D -2 D 2 xn 2 + D 1 xn 1 + D 0 xn 0 + D -1 xn -1 + D -2 xn -2 (N.B.N 0 = 1) Decimal In decimal, there are 10 digits (0,1,2,3,4,5,6,7,8,9), so, for example 2 7 9.3 1 2 x 100 + 7 x 10 + 9 x 1 + 3 x 1/10 + 1 x 1/100 4

Binary In binary, there are 2 digits (0,1), so, for example 1 1 0.1 0 1 x 4 + 1 x 2 + 0 x 1 + 1 x 1/2 + 0 x 1/4 (6.5 in decimal) Hexadecimal In hexadecimal, there are 16 digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) Conversion between binary and decimal can be awkward Conversion between binary and hexadecimal easy: since 4 bits can represent 16 numbers, it can always be represented by a single hexadecimal digit. 5

Four-bit numbers Decimal Binary Hexadecimal Note: 2 digits to represent the numbers in red 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F Note: Only 1 digit for hexadecimal representation Negative integers in binary Clearly, we can represent positive integers in bits What about negative integers? Consider the binary sequence of adding 1 to an integer represented by a byte 6

Negative integers in binary Sequence adding 1 to a byte 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 (254) (255) 1 0 0 0 0 0 0 0 0 Clocked around to zero again! Negative integers in binary Effectively, we have 255 + 1 = 0 (!) So (for a byte) the binary number 1 1 1 1 1 1 1 1 Is equivalent to -1. 7

The sign bit We may take the bit on the far left-handside to be the sign bit. If this is 1, the number is taken to be negative. Sign bit 1 0 1 1 1 1 1 1 (N 1 ) 0 1 0 0 0 0 0 1 (65) Adding these two numbers gives zero. So N 1 = -65 Ones and twos complements Making a binary integer negative Step 1: Form ones complement by inverting (NOT-ing) each digit Step 2: Form twos complement by adding 1. Example: Start with 5 0 0 0 0 0 1 0 1 Invert 1 1 1 1 1 0 1 0 Add 1 1 1 1 1 1 0 1 1 (-5) 8

Range of integer data types Using 1 byte, an integer data type has the range -128 to 127 (-2 7 to 2 7 1) More often, an integer may be represented by 4 bytes (32 bits). This gives a range of -2 7 to 2 31 1 (-2,147,483,648 to 2,147,483,647) Real numbers How do we represent real numbers? We could choose a position in a group of bits to be the location of the binary bit separating the integral part from the fractional part of the number This is the fixed point representation However, fixed point is inherently limited and is not used much 9

Scientific notation (base 10) Consider the scientific notation for representing a number, e.g. 1.3806503 x 10-23 This consists of The mantissa (here 1.3806503) The base (here 10) The exponent (here -23) Changing to base 2 In a digital computer, we use base 2. The number we had earlier may be written as 1.043189872 x 2-76 In binary, the mantissa is 1.1 1110 0010 1101 1101 0000 0111 In fact, we can drop the leading 1 since in this form it will always be there and may be implied. So the mantissa is 1 1110 0010 1101 1101 0000 0111 10

Floating point numbers The mantissa and exponent may now be stored as integers with a sign bit (the mantissa is not usually converted to twos complement form) A number stored in this way is known as a floating point number Typically, such data types are given the name float Precision of floating point numbers Since reals may be irrational (or require more digits than provided) floating point numbers are not necessarily exact (whereas integers are) We can increase the precision by increasing the number of bits used to store the number Typically, a data type known as a double has twice the number of bits as a float 11

Boolean variables A Boolean variable can take one of two values Often interpreted as true and false Examples seen in logic circuits (taking values 1 and 0 However, using 1 byte, it is often the case that 00000000 = false 11111111 = true (i.e. -1) Program control Boolean variables are used to test cases for program control, e.g. start Algorithm for counting from 0 to 9 set x = 0 Note: (x < 10) evaluates to a Boolean variable, i.e. either true or false. x < 10 true false stop set x = x + 1 Coláiste na hollscoile Corcaigh, Éire ROINN ROINN NA NA FISICE Physics 12

Text characters Since we can represent numbers in binary, we can map a number to a printing character. For example ASCII (American Standard Code for Information Interchange) or, more recently, UNICODE Data types in general In general, if a quantity can be represented by a number (or mapped by a number), then it can be represented in digital form and a data type defined for it. 13

Example of data processing Adding two numbers We shall use the XOR gate, shown in the next two slides The XOR gate The XOR or exclusive OR gate has the truth table A B A XOR B 0 0 0 0 1 1 1 0 1 1 1 0 14

The XOR gate in NAND gates The half adder Adds two binary digits, giving the sum (S) and the carry (C) digits 15

The full adder block diagram The full adder logic circuit half adder Full adder logic circuit. Note the half adder circuit within the grey lines 16