Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Pascal/HP-UX Programmer's Guide > Chapter 4 Predefined Pascal Constants, Data Types, and Modules

Bit52

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The predefined data type bit52 is a subrange, 0..252-1, that is stored in 64 bits. bit52 is a unique HP Pascal type because arithmetic operations on bit52 data are performed as unsigned 64-bit integers. Unsigned addition and subtraction do not overflow. Unsigned multiply may overflow. The compiler option OVFLCHECK has no effect.

Note that there are no bit52 constants in the compiler. Therefore, numbers in the range maxint + 1..252 -1 can not be expressed directly. The function hex can be used with the compiler options TYPE_COERCION and RANGE to fill part of this range. The compiler option TYPE_COERCION is also needed when initializing a bit52 constant field. In this case, bit52() is not used. When bit52 is used in an executable statement, RANGE OFF must be used.

For number in the range of 232..252-1, a run-time computation must be done. If the numbers are all constants, they must be type coerced to bit52 so they do not integer overflow.

Variant records can also be used to build up these large constants.

To determine if a type T is assignment compatible with bit52.

  • If variable v is of type T and variable b52 is of type bit52, then the assignment b52 := v is legal if the value of v is within the range 0..252-1.

  • If the ranges of T and bit52 do not overlap, the assignment b52 := v causes a compile-time error.

  • If the ranges of T and bit52 do overlap, but the value of v is outside the range of bit52, then the assignment b52 := v causes a run-time error.

Example

$standard_level 'hp_modcal'$
program prog_bit52(output);

var i : integer;
b : bit52;

type rec = record
f1 : bit52;
end;
$push; type_coercion 'conversion'$
const v_rec = rec[f1: hex('ffffffff')]; { bit52 constant field }
$pop$
begin
b := hex('ffffffff'); { compile-time error }
i := -1;

try
b := i; { run-time error }
recover ;

(Example is continued on next page.)

$push; type_coercion 'conversion'; range off$
b := bit52(i) + 1; { zero is stored }

b := bit52(hex('ffffffff'));
$pop$

try
i := b; { run-time error }
recover ;

try
i := b + i; { b and i are converted to longint and are }
{ too big to fit back into i }
recover ;

i := hex('ffffffff'); { both b and i now have all bits on }

{ the following never prints since i is sign extended to longint and
b is zero extended to longint }
$push; type_coercion 'conversion'$
if longint(i) = b then writeln('equal');
$pop$
end.
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.