Review Topics. Midterm Exam Review Slides. Number Representation What can a binary number mean? Number Representation Hexadecimal to Binary Conversion

Similar documents
DNA Data and Program Representation. Alexandre David

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Useful Number Systems

Number Representation

HOMEWORK # 2 SOLUTIO

The string of digits in the binary number system represents the quantity

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Numbering Systems. InThisAppendix...

Computer Science 281 Binary and Hexadecimal Review

Solution for Homework 2

The programming language C. sws1 1

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

2011, The McGraw-Hill Companies, Inc. Chapter 3

CSI 333 Lecture 1 Number Systems

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Binary Numbers. Binary Octal Hexadecimal

Systems I: Computer Organization and Architecture

Sources: On the Web: Slides will be available on:

Lecture 2. Binary and Hexadecimal Numbers

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Informatica e Sistemi in Tempo Reale

Base Conversion written by Cathy Saxton

Chapter 4: Computer Codes

Chapter 7D The Java Virtual Machine

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

Lecture 11: Number Systems

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Stacks. Linear data structures

Binary Representation

arrays C Programming Language - Arrays

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

ELEG3924 Microprocessor Ch.7 Programming In C

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

C++ Programming Language

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Positional Numbering System

COMPSCI 210. Binary Fractions. Agenda & Reading

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

How To Write Portable Programs In C

CPEN Digital Logic Design Binary Systems

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Chapter 1: Digital Systems and Binary Numbers

Objective-C Tutorial

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Pemrograman Dasar. Basic Elements Of Java

The C Programming Language course syllabus associate level

The Answer to the 14 Most Frequently Asked Modbus Questions

Data Storage: Each time you create a variable in memory, a certain amount of memory is allocated for that variable based on its data type (or class).

Decimal to Binary Conversion

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

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

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

Caml Virtual Machine File & data formats Document version: 1.4

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

B.Sc.(Computer Science) and. B.Sc.(IT) Effective From July 2011

1. Introductory Overview

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

PROBLEMS (Cap. 4 - Istruzioni macchina)

Lecture N -1- PHYS Microcontrollers

The New IoT Standard: Any App for Any Device Using Any Data Format. Mike Weiner Product Manager, Omega DevCloud KORE Telematics

Technical Support Bulletin Nr.18 Modbus Tips

Number Systems and Radix Conversion

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Fast Arithmetic Coding (FastAC) Implementations

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

First Bytes Programming Lab 2

Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java

Object Oriented Software Design

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

2.2: Bitwise Logical Operations

Chapter 5. Binary, octal and hexadecimal numbers

Simple Image File Formats

Version 4 MAT-File Format

Object Oriented Software Design

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

3. Convert a number from one number system to another

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

10CS35: Data Structures Using C

Number and codes in digital systems

Copyright 2012 Pearson Education, Inc. Chapter 1 INTRODUCTION TO COMPUTING AND ENGINEERING PROBLEM SOLVING

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

MS ACCESS DATABASE DATA TYPES

Transcription:

Review Topics Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Base Conversion Floating-Point Math 2 s Complement Arithmetic Bitwise Operators 2 What can a binary number mean? Interpretations of a 32-bit memory location: 32-bit floating point (IEEE) 32-bit unsigned/signed integer 16-bit unsigned/signed integer (2) 8-bit unsigned/signed bytes (4) ASCII characters (4) RISC instruction Control or status register.jpg..mpg,.mp3.,.avi, 3 Hexadecimal to Conversion Method: Convert hexadecimal digits to binary using table. Question: What is hexadecimal 0xFEBD4570 in binary? F E B D 4 5 7 0 1111 1110 1011 1101 0100 0101 0111 0000 Answer: 11111110101111010100010101110000 Hexadecimal 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 4 1

to Hexadecimal Conversion Method: Group binary digits, convert to hex digits using table. Question: What is binary 11001101111011110001001000110000 in hexadecimal? 1100 1101 1110 1111 0001 0010 0011 0000 C D E F 1 2 3 0 Answer: 0xCDEF1230 Hexadecimal 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 A 1010 B 1011 C 1100 D 1101 E 1110 F 1111 5 Decimal to Conversion Method: Convert decimal to binary with divide by 2, check odd/even. Question: What is decimal 49 in binary? 49 is odd, prepend a 1 1 49 / 2 = 24 is even, prepend a 0 01 24 / 2 = 12 is even, prepend a 0 001 12 / 2 = 6 is even, prepend a 0 0001 6 / 2 = 3 is odd, prepend a 1 10001 3 / 2 = 1 is odd, prepend a 1 110001 Answer: 110001 2 n Decimal 2 0 1 2 1 2 2 2 4 2 3 8 2 4 16 2 5 32 2 6 64 2 7 128 2 8 256 2 9 512 2 10 1024 6 to Decimal Conversion Method: Convert binary to decimal by multiplying by 2, add 1 if bit set. Question: What is binary 110101 in decimal? Start with 0 0 Left bit set, multiply by 2, add 1 1 Left bit set, multiply by 2, add 1 3 Left bit clear, multiply by 2 6 Left bit set, multiply by 2, add 1 13 Left bit clear, multiply by 2 26 Left bit set, multiply by 2, add 1 53 Answer: 53 2 n Decimal 2 0 1 2 1 2 2 2 4 2 3 8 2 4 16 2 5 32 2 6 64 2 7 128 2 8 256 2 9 512 2 10 1024 7 to Floating Point Conversion Single-precision IEEE floating point number: 1 01111111 10000000000000000000000 sign exponent fraction Sign is 1 number is negative. Exponent field is 01111111 = 127 127 = 0 (decimal). Fraction is 1.100000000000 = 1.5 (decimal). Value = -1.5 x 2 (127-127) = -1.5 x 2 0 = -1.5 8 2

Floating Point to Conversion Value = 6.125 Number is positive sign is 0 Fraction is 110.001 (binary), normalize to 1.10001 * 2 2 Exponent is 2 + 127 = 129 (decimal) = 10000001 Single-precision IEEE floating point number: 0 10000001 10001000000000000000000 sign exponent fraction 9 Hexadecimal to ASCII Conversion Method: Convert values to ASCII by table lookup. Each two (hex) digits is a single character. Question: What is hex 0x42454144 in ASCII? 0x42 = 'B' 0x45 = 'E' 0x41 = 'A' 0x44 = 'D' Answer: BEAD Char ASCII Code Char ASCII Code 'A' 0x41 '0' 0x30 'B' 0x42 '1' 0x31 'C' 0x43 '2' 0x32 'D' 0x44 '3' 0x33 'E' 0x45 '4' 0x34 'F' 0x46 '5' 0x35 'G' 0x47 '6' 0x36 10 Signed Integer Representations Number Signed Magnitude 1 s Complement 2 s Complement 0000 0 0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000-0 -7-8 1001-1 -6-7 1010-2 -5-6 1011-3 -4-5 1100-4 -3-4 1101-5 -2-3 1110-6 -1-2 1111-7 -0-1 11 2 s Complement Arithmetic Arithmetic (unsigned integers): 1 0 0 1 0 0 1 0 + 0 0 1 1 0 1 0 1 0 1 1 0 0 0 1 1 1 0x92 + 0x35 = 0xC7 Decimal Equivalent: 146 + 53 = 199 Arithmetic (signed integers): 1 0 0 1 0 0 1 0 + 0 0 1 1 0 1 0 1 0 1 1 0 0 0 1 1 1 0x92 + 0x35 = 0xC7 Decimal Equivalent: -110 + 53 = -57 12 3

Bitwise Logical Operations Bitwise AND (&): 1 1 1 1 0 0 0 0 & 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0xF0 & 035 = 0xC0 Bitwise OR ( ): 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 1 0 1 0xF0 035 = 0xF5 Bit Manipulation C code to read or write a bit: int readbit(int value, int bit) { return (value >> bit) & 01; // return!!(value >> bit); void writebit(int *value, int bit) { *value = 1<<bit; 13 14 Control Structures Basic Pointers C conditional and iterative statements if statement if (value == 0x12345678) printf("value matches 0x12345678\n"); for loop for (int i = 0; i < 8; ++i) printf("i = %d\n", i); while loop int j = 6; while (j--) printf("j = %d\n", j); C pointers void foo(int *intp, double *doublep){ *intp = 28; *doublep = 2.34; int main(int argc, char *argv[]) { int i = 17; double d = 1.23; foo(&i, &d); printf( %i, %.2f\n,i, d); // prints 28,2.34 15 16 4

Pointers and Arrays Memory Allocation C pointers and arrays void foo(int *pointer) { *(pointer+0) = pointer[2] = 0x1234; *(pointer+1) = pointer[3] = 0x5678; int main(int argc, char *argv[]) { int array[]= {0, 1, 2, 3; foo(array); for (int i = 0; i <= 3; ++i) printf("array[%d] = %x\n", i, array[i]); Static Allocation char carray[100]; char carray[] = { a, %, 5 ; Dynamic Allocation char *carray = malloc(100 * sizeof(char)); char *carray = calloc(100, sizeof(char)); carray[index] = 1234; free (carray); 17 18 5