chapter 2 bits, data types, and operations

4
Chapter 2 Bits, Data Types, and Operations

Upload: breanna-daugherty

Post on 30-Dec-2015

24 views

Category:

Documents


1 download

DESCRIPTION

Chapter 2 Bits, Data Types, and Operations. Hexadecimal Notation. It is often convenient to write binary (base-2) numbers as hexadecimal (base-16) numbers instead. fewer digits -- four bits per hex digit less error prone -- easy to corrupt long string of 1 ’ s and 0 ’ s. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 2 Bits, Data Types, and Operations

Chapter 2Bits, Data Types,and Operations

Page 2: Chapter 2 Bits, Data Types, and Operations

2-2

Hexadecimal NotationIt is often convenient to write binary (base-2) numbersas hexadecimal (base-16) numbers instead.

• fewer digits -- four bits per hex digit• less error prone -- easy to corrupt long string of 1’s and 0’s

Binary Hex Decimal0000 0 0

0001 1 1

0010 2 2

0011 3 3

0100 4 4

0101 5 5

0110 6 6

0111 7 7

Binary Hex Decimal1000 8 8

1001 9 9

1010 A 10

1011 B 11

1100 C 12

1101 D 13

1110 E 14

1111 F 15

Page 3: Chapter 2 Bits, Data Types, and Operations

2-3

Convert Hexadecimal (2’s C binary) to DecimalGiven a hex digit that represents 2’s complement binary, convert into a decimal.

Example: 6Fhex or x6F

1. Determine the sign of the number. If the msh (most significant hex) value is 8 or greater then the sign is negative.

6Fhex, sign + b/c msh (6) < 8sign positive

2. Use positional notation to convert6x161 + Fx160 = 6x161 + 15 = 96 + 15 = 111 6Fhex = 111ten

Page 4: Chapter 2 Bits, Data Types, and Operations

2-4

Convert Hexadecimal (2’s C binary) to DecimalGiven a hex digit that represents 2’s complement binary, convert into a decimal.

Example: A0Fhex or xA0F

1. Determine the sign of the number. If the msh (most significant hex) value is 8 or greater then the sign is negative.

A0Fhex, sign - b/c msh (A) < 8sign negative

2. Since negative, must apply 2’s complement

3. Convert to signed magnitude to decimal with positional notation-(5x162 + Fx161 + 1x160) = -(5x256 + 15x16 + 1) = -1,521

FFF- A0F5F0

5F0+ 15F1

A0F = - 5F1