Mechanical Engineering EMCH 367
EMCH 367
Engineering, USC

HOME
SCHEDULE
DEMO'S
HANDOUTS
LABS
PROJECT
USEFUL LINKS
VALUABLE INFORMATION





HOME NEXT BACK


Note
The following documentation is also provided with the relevant labs.
Please click on lab links to obtain the printable versions ( PDF files ) of those labs.



Binary and Hex Number

What are binary numbers and why do we use them?

The Binary System

1

1

0

0

0

0

1

1

1

1

0

0

1

1

0

0

1

0

0

0

1

 

Decimal to Binary Conversion:

The remainder 1 resulting from the last division is the MSB, while the first remainder is the LSB of the conversion. From this example we see that the decimal number 132 is equal to the binary number 10000100.

Hexadecimal (Hex) Representation:

Arithmetic Operations

The rules for addition of binary numbers are straightforward:

0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 0 with a carry of 1, i.e. 1 + 1 = 102.

Negative Numbers in the Computer

Until now, we have discussed only positive numbers. These numbers were called "unsigned 8-bit integers". In an 8-bit byte, we can represent a set of 256 positive numbers in the range 010-25510. However, in many operations it is necessary to also have negative numbers. For this purpose, we introduce "signed 8-bit integers". Since we are limited to 8-bit representation, we remain also limited to a total of 256 numbers. However, half of them will be negative (-12810 through -110) and half will be positive (010 through 12810).

The representation of signed (positive and negative) numbers in the computer is done through the so-called 8-bit 2's complement representation. In this representation, the 8th bit indicates the sign of the number (0 = +, 1 = -).

The signed binary numbers must conform to the obvious laws of signed arithmetic. For example, in signed decimal arithmetic, -310 + 310 = 010. When performing signed binary arithmetic, the same cancellation law must be verified. This is assured when constructing the 2's complement negative binary numbers through the following rule:

To find the negative of a number in 8-bit 2's complement representation, simply subtract the number from zero, i.e. -X = 0 - X using 8-bit binary arithmetic.

Example 1: Use the above rule to represent in 8-bit 2's complement the number -310

Solution: Subtract the 8-bit binary representation of 310 from the 8-bit binary representation of 010 using 8-bit arithmetic (8-bit arithmetic implies that you can liberally take from, or carry into the 9th bit, since only the first 8 bits count!).

BINARY DECIMAL 00000000 - 010 - 00000011 310 11111101 -310

Note that, in this operation, a 1 was liberally borrowed from the 9th bit and used in the subtraction!Verification We have establish that -310 = 111111012. Verify that -310 + 310 = 010 using 8-bit arithmetic. BINARY DECIMAL 11111101 - -310 - 00000011 310 00000000 010Note that, in this operation, a carry of 1 was liberally lost in the 9th bit!

Example 2: Given the binary number 00110101, find it's 2's complement.

Verification: 01110101 + 10001011 = (1)00000000. Since the 9th bit is irrelevant, the answer is actually 00000000, as expected

The rule outlined above can be applied to both binary and hex numbers.

 

Example 3: Given the hex number 6A, find its 8-bit 2's complement.

Solution: Subtract the number from 0016 using 8-bit arithmetic:

Verification: 6A16 + 9616 = (1)00. Since the 9th binary bit is irrelevant, the answer is actually 0016, as expected

Numerical Conversion Chart for unsigned 8-bit binary integers

Decimal (base 10)

4-bit binary (base 2)

Hex (base 16)

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

 

 

Numerical Conversion Chart for 2's complement signed 8-bit binary integers

Decimal

8-bit 2's complement
signed binary

Hex

+127

0111 1111

7F

+16

0001 0000

10

+15

0000 1111

0F

+14

0000 1110

0E

+13

0000 1101

0D

+12

0000 1100

0C

+11

0000 1011

0B

+10

0000 1010

0A

+9

0000 1001

09

+8

0000 1000

08

+7

0000 0111

07

+6

0000 0110

06

+5

0000 0101

05

+4

0000 0100

04

+3

0000 0011

03

+2

0000 0010

02

+1

0000 0001

01

0

0000 0000

00

-1

1111 1111

FF

-2

1111 1110

FE

-3

1111 1101

FD

-4

1111 1100

FC

-5

1111 1011

FB

-6

1111 1010

FA

-7

1111 1001

F9

-8

1111 1000

F8

-9

1111 0111

F7

-10

1111 0110

F6

-11

1111 0101

F5

-12

1111 0100

F4

-13

1111 0011

F3

-14

1111 0010

F2

-15

1111 0001

F1

-16

1111 0000

F0

-128

1000 0000

80



TOP HOME NEXT BACK