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

Bit32

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The predefined data type bit32 is a subrange, 0..232-1, that is stored in 32 bits. bit32 is a unique HP Pascal type because arithmetic operations on bit32 data are performed as unsigned 32-bit integers. Unsigned addition and subtraction do not overflow. Unsigned multiply can overflow unless the compiler option OVFLCHECK is used.

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

To determine if a type T is assignment compatible with bit32:

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

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

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

Example

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

var i : integer;
b : bit32;

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

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

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

b := bit32(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 }
if i = b then writeln('equal');
end.
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.