Difference between revisions of "BitSizeOf"
m |
m (use proper singular of data) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{LanguageBar}} | {{LanguageBar}} | ||
− | The compiler intrinsic function '''<syntaxhighlight lang="pascal" inline>bitSizeOf</syntaxhighlight>''' returns the size of a | + | The compiler intrinsic function '''<syntaxhighlight lang="pascal" inline>bitSizeOf</syntaxhighlight>''' returns the size of a datum in bits. |
== definition == | == definition == |
Latest revision as of 12:25, 3 July 2021
│ Deutsch (de) │ English (en) │
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:
[math]\displaystyle{ \texttt{sizeOf}(\texttt{x}) = \lceil \, \texttt{bitSizeOf}(\texttt{x}) \; / \; 8 \, \rceil }[/math]
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.