Jump to page titleUNITED STATES
hp.com home products and services support and drivers solutions how to buy
» contact hp

:

more options
 

hp.com home
End of Jump to page title
PLI Problem Converting Variables To Bit Strings
Jump to content



» 

business support center

Home & Home Office Support:
» HP branded products
» Presario branded products
» Services & Warranties
Small & Medium Business Support:
» Small & Medium Business products
» Small & Medium Business services
Support for IT Professionals:
» Enterprise products (IT Resource Center)
» NonStop enterprise products
» Business & IT Services
Content starts here
Copyright (c) Digital Equipment Corporation 1988. All rights reserved
LAYERED PRODUCT: PL/I V3.1, V3.2    OP/SYS: VMS V5.0


SOURCE:     Digital Customer Support Center


SYMPTOM:

When performing implicit or explicit bit conversion, the resultant
bit string value does not contain the correct value.  That is, if a
fixed binary(31) field is moved to or converted with the BIT function,
to a BIT(32) field, the bit string appears to contain an incorrect
value.  The program below demonstrates the problem.  The index I varies
from 0 to 20.  However, when the integer string is converted to
bit and then back, the value is twice what it should be.

bitck: proc options(main);

dcl i fixed bin(31);
dcl bin_field fixed binary(31);
dcl bit_field BIT(32) ALIGNED;
dcl bini_field fixed binary(31);
dcl biti_field BIT(32) ALIGNED;
dcl bine_field fixed binary(31);
dcl bite_field BIT(32) ALIGNED;

 /*explicit conversions*/
 put skip list('Explicit conversions');
 do i  = 0 to 20;
    bite_field = bit(i);
    bine_field = bin(bite_field);
    put skip list(i,bite_field,bine_field);
 end;
 put skip list('implicit conversions');
 /*implicit conversions*/
 do i  = 0 to 20;
    biti_field = bit(i);
    bini_field = bin(biti_field);
    put skip list(i,biti_field,bini_field);
 end;
 put skip list('INT conversions');
 /*int conversions*/
 do i  = 0 to 20;
    bit_field = bit(i);
    bin_field = int((reverse(bit_field)),1,32);
    put skip list(i,bit_field,bin_field);
 end;
end bitck;


ANALYSIS:

The problem lies the the way integer-to-bit conversions are done.
According to the PLI 3.0 Language Reference Manual, page 226.

     If the length of the target bit-string value is greater than
     the length of the intermediate string, the target string is padded
     with zeroes on the right.

For a fixed bin(r,s), the precision of the bit string is calculated as
follows:   min(31,(r-s)).  In this case, 31.


SOLUTION:

The solution to this problem is to force the two variables to have
the same length.

        The only difference between this program and the previous one
        is that the 3 declared variables of type BIT ALIGNED is of length 31
        here, whereas it was length of 32 in the previous one.

bitck: proc options(main);

dcl i fixed bin(31);
dcl bin_field fixed binary(31);
dcl bit_field BIT(31) ALIGNED;
dcl bini_field fixed binary(31);
dcl biti_field BIT(31) ALIGNED;
dcl bine_field fixed binary(31);
dcl bite_field BIT(31) ALIGNED;

 /*explicit conversions*/
 put skip list('Explicit conversions');
 do i  = 0 to 20;
    bite_field = bit(i);
    bine_field = bin(bite_field);
    put skip list(i,bite_field,bine_field);
 end;
 put skip list('implicit conversions');
 /*implicit conversions*/
 do i  = 0 to 20;
    biti_field = bit(i);
    bini_field = bin(biti_field);
    put skip list(i,biti_field,bini_field);
 end;
 put skip list('INT conversions');
 /*int conversions*/
 do i  = 0 to 20;
    bit_field = bit(i);
    bin_field = int((reverse(bit_field)),1,32);
    put skip list(i,bit_field,bin_field);
 end;
end bitck;





buy online or call 1.800.AT.COMPAQ
privacy statementusing this site means you accept its terms