History Conversion: Integers - Lecture Notes | AER E 161, Study notes of Aerospace Engineering

Material Type: Notes; Professor: Haugli; Class: NUM&GRAPHC&LAB TCNQ; Subject: AEROSPACE ENGINEERING; University: Iowa State University; Term: Spring 2005;

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-yn5-1
koofers-user-yn5-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
D. Haugli, Lecturer Aer E 161 Aerospace Engineering
2/3/2005 Binary Conversion: Integers, Page 1 Iowa State University
Binary Conversion: Integers
This document demonstrates how to convert a base-10 integer to binary and back. In this
document, 2
n represents a binary number, 10
n a base-10 integer, and
γ
the highest, integer power
of 2 that fits into 10
n.
A search of the web indicates that two procedures are typically used to convert a base-10 number
to binary. The first procedure involves subtracting powers of 2 from the base 10 number, and the
second involves dividing the base-10 number repeatedly by 2.
The conversion from a base-10 integer to binary is exact and does not involve round-off errors.
Subtraction Procedure. The subtraction procedure depends on determining
γ
such that
γ
2 will
fit into the base-10 number (or its remainder) without exceeding it. Mathematically, this
statement is equivalent to:
1
210 =
γ
n, (1)
where any digits to the right of the decimal have been truncated.
Rearrange this equation and apply the property of logs to find
γ
.
,log2log
,log2log
,2
10
10
10
x
x
x
=
=
=
γ
γ
γ
2log
log 10
x
=
γ
. (2)
The subtraction procedure is:
1. Determine
γ
from Equation (2).
2. Evaluate the remainder:
γ
2
1010 = nn .
3. Return to Step 1, computing the next highest power of 2 that will fit into the remainder.
Repeat Steps 1 and 2 until the remainder is 0. Keep track of each power of 2 that fits into
each remainder.
4. Assemble the binary number, 2
n, beginning with the highest power of two on the left.
The procedure is most easily completed with a table, as shown in Example 1.
pf3

Partial preview of the text

Download History Conversion: Integers - Lecture Notes | AER E 161 and more Study notes Aerospace Engineering in PDF only on Docsity!

D. Haugli, Lecturer Aer E 161 Aerospace Engineering

Binary Conversion: Integers

This document demonstrates how to convert a base-10 integer to binary and back. In this

document, n 2 represents a binary number, n 10 a base-10 integer, and γ the highest, integer power

of 2 that fits into n 10.

A search of the web indicates that two procedures are typically used to convert a base-10 number

to binary. The first procedure involves subtracting powers of 2 from the base 10 number, and the

second involves dividing the base-10 number repeatedly by 2.

The conversion from a base-10 integer to binary is exact and does not involve round-off errors.

Subtraction Procedure. The subtraction procedure depends on determining γ such that

γ

2 will

fit into the base-10 number (or its remainder) without exceeding it. Mathematically, this

statement is equivalent to:

γ

n

where any digits to the right of the decimal have been truncated.

Rearrange this equation and apply the property of logs to find γ.

log 2 log ,

log 2 log ,

10

10

10

x

x

x

γ

γ

γ

log 2

log x 10

The subtraction procedure is:

1. Determine γ from Equation (2).

2. Evaluate the remainder: n 10 = n 10 − 2 γ.

3. Return to Step 1, computing the next highest power of 2 that will fit into the remainder.

Repeat Steps 1 and 2 until the remainder is 0. Keep track of each power of 2 that fits into

each remainder.

4. Assemble the binary number, n 2 , beginning with the highest power of two on the left.

The procedure is most easily completed with a table, as shown in Example 1.

D. Haugli, Lecturer Aer E 161 Aerospace Engineering

Example 1. Convert 1296 10 to binary. In the following table, “Bit” stores tracks powers

of 2.

Power of 2

Base-

Equivalent Bit Balance

(^10 1024 1 1297) – 1 x 1024 = 273 (^9 512 0 273) – 0 x 512 = 273 (^8 256 1 273) – 1 x 256 = 17 (^7 128 0 273) – 0 x 128 = 17 (^6 64 0 273) – 0 x 64 = 17 (^5 32 0 273) – 0 x 32 = 17 (^4 16 1 273) – 1 x 16 = 1 (^3 8 0 273) – 0 x 8 = 1 (^2 4 0 273) – 0 x 4 = 1 (^1 2 0 273) – 0 x 2 = 1 (^0 1 1 273) – 1 x 1 = 1

With the highest power on the left, the binary number is n 2 = 101000100012.

Division Procedure. The division procedure is:

1. Compute n 10 2 using integer division (truncate digits to the right of the decimal) and

determine the remainder (0 or 1). Repeat, keeping track of each remainder, until the quotient

is zero.

2. Assemble the binary number, with the last remainder on the left and the first on the right.

Example 2. Repeat Example 1 with the division procedure.

Balance Remainder (Bit)

1297/2 = (^648 1297) - 2 x 648 = 1 648/2 = (^324 648) – 2 x 324 = 0 324/2 = (^162 324) – 2 x 162 = 0 162/2 = (^81 162) – 2 x 81 = 0 81/2 = (^40 81) – 2 x 40 = 1 40/2 = (^20 40) – 2 x 20 = 0 20/2 = (^10 20) – 2 x 10 = 0 10/2 = (^5 10) – 2 x 5 = 0 5/2 = (^2 5) – 2 x 2 = 1 2/2 = (^1 2) – 2 x 1 = 0 1/2 = (^0 1) – 2 x 0 = 1

With the last remainder on the left, the binary number is n 2 = 101000100012.

The corresponding power of two is less obvious with the division procedure than with the

subtraction procedure, but the binary result is the same.