Vous êtes sur la page 1sur 6

Lab 2.

BINARY INTEGER REPRESENTATION. NORMAL VALUES.

A binary (radix 2), integer, unsigned, n-bit number is written as:

N

b

n

1

b b

1

0

n 1

i 0

b

i

2

i

(1)

where: N is the number value

b

i are the n bits (BIT = Binary digiT , rom: cifră binară)

b

n is the MSB = Most Significant Bit (rom: cel mai

semnificativ bit)

b

0 is the LSB = Least Significant Bit (rom: cel mai puţin

semnificativ bit)

The binary dot (or comma) is supposed, by default, on the right side of LSB (integer number). The normal binary unsigned representation is often used:

A

0,

a a

1

2

a

n

1

a

n

n

i 1

a

i

2

i

(2)

where: A[0,1) is the normal binary number

a i are the n bits

a 1 is the MSB

a n is the LSB

The binary dot (or comma) is supposed, by default, on the left side of MSB (fractional number). In electronic circuits, the bits are transmitted either parallel (simultaneous in time, on separate electric lines), or serial (sequentially in time, on the same electric line). Regardless the transmission mode, the dot position information is not encoded. The dot position is supposed fix,

1

Data Conversion and Acquisition Systems - Lab Manual

established by the used convention. (There are floating point representations, in “mantissa + exponent” format, unusual in D/A and A/D conversion, and which are not considered in this work). The same bit string can be seen as an integer (as in (1)) or fractional (normal) number (as in

(2)). For b n-i = a i i=1

n,

the two representations are tied by:

n

N 2 A

(3)

That is because, changing from A to N supposes binary dot movement over n positions, meaning multiplication by n-th power of the radix (2). For bipolar (signed) number representation, an additional bit (sign bit) is needed. Several bipolar codes are currently used, shown in table 1. Based on an unsigned (unipolar) 3 bit code, the fourth (sign) bit was added. Preferably, the sign bit is 0 for “+” sign, and 1 for “–” sign (BO code is an exception). This way, positive numbers are similar (sign bit read as an meaningless 0) to the same value in the unsigned code. SM Code (Signed Magnitude) (rom: MS = Mărime şi Semn), splits the bit string in two distinct fields: sign (MSB) and absolute value (all the other bits). Two numbers, of opposite signs but same absolute value, have complementary sign bits, and all the other bits identical. 1sC code (1s Complement) (rom: C1 = Complement faţă de 1) has positive numbers identical to SM ones. A negative number is the bit-by-bit complement of the positive same absolute value number. SM and 1sC codes have distinct representations for 0, respective

+0.

BO code (Binary Offset) (rom. BD = Binar Deplasat) assigns a single representation for 0 and +0. It is built by sliding half-the-way the binary unipolar n+1 bit code (4 bit in the example), such a way that the

middle point of the table (100

2sC code (2s complement) (rom: C2 = complement faţă de 2), the most used one, has the sign bit complemented compared to BO. BO and 2sC use a single representation for 0 value (regardless the sign), the freed bit combination is assigned to 2 n value, not available for

00),

to correspond to the 0 value.

2

Binary integer representation. Normal values

SM and 1sC codes. No bipolar code can write +2 n on n+1 bits, as no unipolar code can write it on n bits.

Value

Unipolar

code

Signed

magnitude

1’s

complement

Binary offset

(BO)

2’s

complement

(SM)

(1’s C)

(2’s C)

8

7

111

0111

0111

1111

0111

6

110

0110

0110

1110

0110

5

101

0101

0101

1101

0101

4

100

0100

0100

1100

0100

3

011

0011

0011

1011

0011

2

010

0010

0010

1010

0010

1

001

0001

0001

1001

0001

0

000

0000

0000

1000

0000

-0

1000

1111

-1

1001

1110

0111

1111

-2

1010

1101

0110

1110

-3

1011

1100

0101

1101

-4

1100

1011

0100

1100

-5

1101

1010

0011

1011

-6

1110

1001

0010

1010

-7

1111

1000

0001

1001

-8

0000

1000

Table 1. Bipolar binary codes

3

Data Conversion and Acquisition Systems - Lab Manual

LAB PURPOSE

The lab intends to familiarize the students to several types of binary integer codes. The working software acts as a “calculator” showing simultaneously the desired value as:

decimal number

binary number

- signed magnitude (SM) code;

- 1’s complement (1’s C) code;

- binary offset (BO) code;

- 2’s complement (2’ C) code;

hexadecimal number, corresponding to 2’s complement binary code.

Either of these representations can act as value INPUT, selected by pressing the associate button. The input value is translated in all the other available codes. For decimal or hexadecimal input values, the edit field can be selected using the mouse or Tab-key. Enter-key or click outside the edit field confirms the value. For user convenience, in binary representations, each bit is direcly accessible using the mouse. Fig. 1 shows the lab software user interface.

THE NUMBER OF USED BITS

For binary codes, the representation number of bits is essential. It can be chosen (for all the binary representations) using the control button, and includes the sign bit. The available range is 1 … 32 (allowing integer numbers between [-2 32 ; +2 32 1]). The sign bit (MSB) is shown in different color (to emphase its different meaning).

4

Binary integer representation. Normal values

Binary integer representation. Normal values Fig. 1 The user interface. For binary input data, the program

Fig. 1 The user interface.

For binary input data, the program only allows using the selected number of bits. However, for decimal or hexadecimal input data, if the selected number of bits is to small, the binary values are correctly displayed, using the minimum number of bits. The additional needed bits are “shadowed”, and visual (and eventually acoustic) alarm is generated.

SM and 1’s C codes generate different bit patterns for +0 and 0. To emphasize this, if the input value is 0, the two alternative patterns are displayed alternatively.

5

Data Conversion and Acquisition Systems - Lab Manual

The

HELP

button

opens

a

window

that

shortly describes

the

conversion algorithms for the considered integer codes.

THE LAB FLOW:

Analyzing each binary integer bipolar code, discussing the specific advantages and disadvantages;

Studying the basic conversion steps from each code to each other pay attention to the building of each code;

Understanding the meaning of “normal values”;

Identifying fast, simplified conversion algorithms from each code to each other;

Practicing the previous found algorithms, verifying the results with the program generated values.

Evaluating the earned knowledge running the TEST command. The test

supposes performing in a limited time interval (30 min.) the random generated conversion requests. All possible code pairs (source destination) are scanned in a random sequence, using random values. Each answer is marked (true or false). After the allocated time, or after the last answer, the program grades the test on a 1 to 10 scale. The Abandon button allows quitting the test at any time (returning to the main program).

6