Chapter 2
C Language Reference
©
National Instruments Corporation
2-41
Align the radix positions of
n1
and
n2
to the radix position of the result
before subtracting (that is, shift
n1
left by three bits, and shift
n2
left by
two bits). Place the aligned results in
n1'
and
n2'
and perform a 16-bit
subtraction of
n1'
and
n2'
, and store the result in
n3'
:
00000000 1^0001000
(
n1' = (136,r7)
, decimal value = 1.0625)
—
00000000 1^0000000
(
n2' = (128,r7)
, decimal value = 1.0)
_______________________
00000000 0^0001000
(
n3' = (8,r7)
, decimal value = .0625)
Change the result back to an 8-bit signed number in
n3
:
0^0001000
(
n2 = (8,r7)
, decimal value = .0625)
Method 2: Not Using Wordsize Extension
In binary representation:
0001^0001
(
n1 = (17,r4)
, decimal value = 1.0625)
—
001^00000
(
n2 = (32,r5)
, decimal value = 1.0)
Align the radix positions of
n1
and
n2
to the radix position of the result
before subtracting (that is, shift
n1
left by three bits, and shift
n2
left by
two bits). Place the aligned results in
n1'
and
n2'
and perform an 8-bit
subtraction of
n1'
and
n2'
, and store the result in
n3
:
sign bit
|
0001^0001
(
n1 = (17,r4)
, decimal value = 1.0625)
Detect overflow before aligning to radix position 7, correct overflow (that
is, use maximum number possible)
0^1111111
(
n1' = (127,r7)
, decimal value = .9921875)
001^00000
(
n2 = (32,r5)
, decimal value = 1.0)
Detect overflow before aligning to radix position 7, correct overflow (that
is, use maximum number possible)
0^1111111
(
n2' = (127,r7)
, decimal value = .9921875)
0^1111111
(
n1' = (127,r7)
, decimal value = .9921875)
—