BitSizeOf
Deutsch · English
The compiler intrinsic function bitSizeOf returns the size of a datum in bits.
definition
BitSizeOf produces different results only for members of bitpacked structures. In all other cases the result of bitSizeOf is simply 8 * sizeOf(x) (or sizeOf(x) shl 3). To put this relation in other words:
$\texttt{sizeOf}(\texttt{x}) = \lceil \, \texttt{bitSizeOf}(\texttt{x}) \; / \; 8 \, \rceil$
application
In some cases using bitSizeOf can improve your code’s readability:
program binaryPrint(input, output, stdErr);
var
(* in FPC `integer` definition *)
(* depends on the selected mode *)
i: integer;
begin
readLn(i);
writeLn(binStr(i, bitSizeOf(i)));
end.If your code makes presumptions about memory requirements, e. g. by using an algorithm exploiting certain properties of your bitpacked data type, you may want to safeguard your code with some conditional compilation, may be even just for documentation purposes.
see also
From the Free Pascal wiki, page "BitSizeOf", as it stood on 2021-07-03 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
