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

Similar documents
Module 1: Information Representation I -- Number Systems

Electronic Data and Instructions

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2

Binary Codes. Dr. Mudathir A. Fagiri

Number System. Introduction. Decimal Numbers

Final Labs and Tutors

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

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

Intermediate Programming & Design (C++) Notation

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

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

Signed Binary Numbers

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

MACHINE LEVEL REPRESENTATION OF DATA

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

Harry H. Porter, 2006

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

CMPE223/CMSE222 Digital Logic Design. Positional representation

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

Chapter 1 Emad Felemban

Module 2: Computer Arithmetic

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

CS & IT Conversions. Magnitude 10,000 1,

Experimental Methods I

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2007/09/17. with slides by Kip Irvine

Number representations

Survey. Motivation 29.5 / 40 class is required

COMP2611: Computer Organization. Data Representation

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

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

Chapter 2 Number System

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College September 6, 2018

T02 Tutorial Slides for Week 2

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Representation of Information

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

Course Syllabus [1/2]

COMP Overview of Tutorial #2

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

Inf2C - Computer Systems Lecture 2 Data Representation

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

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor

COMP2121: Microprocessors and Interfacing. Number Systems

What Is It? Instruction Register Address Register Data Register

Level ISA3: Information Representation

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Printing this Slide Show

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

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

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College January 27, 2015

User. Application program. Interfaces. Operating system. Hardware

Information Science 1

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

CC411: Introduction To Microprocessors

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

CS 101: Computer Programming and Utilization

CMSC 104 -Lecture 2 John Y. Park, adapted by C Grasso

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

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

REPRESENTING INFORMATION:

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

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

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

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

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

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

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

Dec Hex Bin ORG ; ZERO. Introduction To Computing

World Inside a Computer is Binary

Number Representations

Topic Notes: Bits and Bytes and Numbers

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

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Numbers and Representations

Octal and Hexadecimal Integers

LOGIC DESIGN. Dr. Mahmoud Abo_elfetouh

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

Topic Notes: Bits and Bytes and Numbers

CHW 261: Logic Design

EE292: Fundamentals of ECE

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

Octal & Hexadecimal Number Systems. Digital Electronics

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

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

Chapter 1 Preliminaries

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

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Memory Addressing, Binary, and Hexadecimal Review

Lecture 2: Number Systems

Microprocessors I MICROCOMPUTERS AND MICROPROCESSORS

ECE 372 Microcontroller Design Assembly Programming Arrays. ECE 372 Microcontroller Design Assembly Programming Arrays

Computer Organization and Assembly Language. Lab Session 01

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Binary Arithme-c CS 64: Computer Organiza-on and Design Logic Lecture #2

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

Binary Representations and Arithmetic

Introduction to the Use of Computers

Transcription:

Binary Digits (bits) data within a computer system are stored in one of 2 physical states (hence the use of binary digits) 0V and 5V charge / NO charge on a transistor gate ferrite core magnetised clockwise or counter clockwise binary digits (bits) and are represented by the values 0 and 1 binary digits are normally grouped together so they are easier to work with 4 bits = nibble or nybble intel 1110 16 bits = WORD 8 bits = byte (or 2 nibbles) 32 bits = DWORD (double word) 01101001 16 bits = halfword (or 2 bytes) 01111000 01001011 32 bits = word (or 4 bytes) 11101101 01111101 01100111 01100101 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 1

Unsigned Binary Integers unsigned == positive integers ONLY converting binary to decimal 100101 2 base 2 (assume base 10 if not specified) 2 5 =32 2 4 =16 2 3 =8 2 2 =4 2 1 =2 2 0 =1 100101 2 = 1 2 5 + 0 2 4 + 0 2 3 + 1 2 2 + 0 2 1 + 1 2 0 100101 2 = 32 + 0 + 0 + 4 + 0 + 1 100101 2 = 37 similar decimal calculation (base 10) 37 = 3 10 1 + 7 10 0 403 = 4 10 2 + 0 10 1 + 3 10 0 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 2

Converting a positive decimal integer to binary keep dividing by 2 until 0 and remember remainders convert 37 to binary 2 2 2 2 2 2 37 18 9 4 2 1 0 1 0 1 0 0 1 37 2 = 18 remainder 1 read from bottom 37 = 0010 0101 2 what is 42 in binary? what is 16 in binary? 0010 1010 2 0001 0000 2 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 3

pictorial view of a 4 bit unsigned binary integer 1110 1111 15 0000 0000 1 0001 0010 4 bit unsigned binary integer range 1101 13 14 2 3 0011 0000 2 to 1111 2 0 to 15 1100 12 4 0100 n bit unsigned binary integer range 1011 11 10 6 5 0101 0 to 2 n -1 1010 9 8 7 0110 1001 1000 0111 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 4

There are 10 2 types of people in the world: those who understand binary and those who don t. CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 5

Signed Binary Integers SIGNED = positive and negative integers 2's complement notation convert +5 to -5 by taking the 2's complement (invert bits and add 1) 5 0101 2 invert bits 1010 2 add 1 0001 2-5 1011 2 invert bits 0100 2 add 1 0001 2 5 0101 2 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 6

Signed Binary Integers same effect achieved by subtracting from 0 (modulo 16 in this case) zero 0000 2 subtract 5 0101 2 ignore bits beyond the first 4 4 bit signed binary integer -5 1011 2 positive range 0000 2 to 0111 2 0 to 7 negative range 1111 2 to 1000 2-1 to -8 n bit signed binary integer range: -2 n-1 to 2 n-1 1 most significant bit (MSB) indicates sign (0 - positive, 1 - negative) note asymmetrical range only one zero (do have a +0 and a -0) CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 7

pictorial view of a 4 bit signed binary integer 1111 0000 0001 if unsigned, inner ring would have values 0 to 15 1101 1110-2 -1 0000 1 2 0010 0011 value depends whether the binary numbers are interpreted as unsigned or signed (the programmer should know!) 1100 1011-3 -4-5 3 5 4 0100 0101 2 s complement notation used because the same CPU hardware can perform unsigned and signed binary arithmetic simultaneously 1010-6 1001-7 -8 1000 7 0111 6 0110 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 8

Try these what is -42 in binary? +42 invert bits and add 1 0010 1010 2 1101 0110 2 what is -16 in binary? +16 invert bits and add 1 0001 0000 2 1111 0000 2 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 9

Hexadecimal Notation base 16 easier to handle large binary numbers by grouping 4 binary bits into a hexadecimal digit (starting at the least significant bit) consider the following 16 bit unsigned binary integer 1111 1010 1100 1110 2 = FACE 16 F 16 3 + A 16 2 + C 16 1 + E 16 0 15 16 3 + 10 16 2 + 12 16 1 + 14 16 0 15 4096 + 10 256 + 12 16 + 14 1 64,206 what about? 0000 1011 1010 1101 2 = 0BAD 16 0 16 3 + 11 16 2 + 10 16 1 + 13 16 0 2,989 BINARY DEC HEX 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 10

Try this what decimal value is FACE 16 if interpreted as a 16 bit signed integer? MSB is 1, hence negative so take 2 s complement by inverting bits and adding 1 FACE 16 invert bits 0531 16 add 1 0532 16 convert 0532 16 to decimal 0 16 3 + 5 16 2 + 3 16 1 + 2 16 0 1,330 FACE 16 when interpreted as a 16 bit signed integer = -1,330 BINARY DEC HEX 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 11

Decimal to hexadecimal conversion convert 20,085 to hexadecimal keep dividing by 16 until 0 and remember remainders 16 16 16 16 20085 1255 78 4 0 5 7 E 4 20085 16 = 1255 remainder 5 read from bottom 20,085 = 4E75 16 convert -20,085 to hexadecimal (assume 16 bit signed integer) 20,085 4E75 16 invert bits B18A 16 add 1 0001 16-20,085 B18B 16 BINARY DEC HEX 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 12

Alternative notation when writing ARM Assembly Language, can use the following notion for decimal, hexadecimal and binary integers 1000 no prefix usually means decimal 0x1000 hexadecimal (also used by C/C++ and Java) &1000 alternative hexadecimal notation 2_1000 binary n_1000 base n eg. 8_777 is octal (base 8) CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 13

Adding Hexadecimal Numbers compute 0xA89F + 0x09A1 unsigned signed A89F 16 43,167-22,369 + 09A1 16 2,465 2,465 B240 16 45,632-19,904 remember hexadecimal/binary numbers can be interpreted as being unsigned or signed BINARY DEC HEX 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 14

Subtracting Hexadecimal Numbers compute 0xA89F - 0x09A1 unsigned signed A89F 16 43,167-22,369-09A1 16 2,465 2,465 9EFE 16 40,702-24,834 remember hexadecimal/binary numbers can be interpreted as being unsigned or signed BINARY DEC HEX 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 15

Real Binary Numbers binary point (rather than a decimal point) what is the value of the following binary number? 11.010101 2 2 1 =2 2 0 =1 2-1 =0.5 2-2 =0.25 2-3 =0.125 2-4 =0.0625 2 + 1 + 0.25 + 0.0625 + 0.015625 = 3.328125 shows how real numbers can be represented as floating point binary numbers inside a computer, but further detail is beyond the scope of CS1021 CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 16

Larger units larger units of information 1 kilobyte (KB) = 2 10 bytes = 1,024 bytes 1 megabyte (MB) = 1024 x 1024 bytes = 1,024 KB = 2 20 bytes = 1,048,576 bytes 1 gigabyte (GB) = 1,024 MB = 2 30 bytes = 1,073,741,824 bytes 1 terabyte (TB) = 1024 GB = 2 40 bytes = 1,099,511,627,776 bytes the following units are used when expressing data rates (eg. Mb/s note the lowercase b) 1 kilobit (Kb/s) = 1,000 bits per second 1 megabit (Mb/s) = 1,000 kilobits = 1,000,000 bits per second IEC prefixes KiB, MiB, GiB, used to differentiate between 1000 and 1024 technically 1KB = 1000 bytes and 1KiB = 1024bytes (although KB is often used to mean 1024) CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 17

Programmer Calculator many calculators have a programmer mode (eg. Windows 10 calculator) for performing binary and hexadecimal arithmetic don t use one until you know how to do the calculations by hand calculators NOT allowed in the CS1021 mid-term test or exams CS1021 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College Dublin 18-Sep-18 18