Difference between revisions of "BitSizeOf"

From Free Pascal wiki
Jump to navigationJump to search
m
m (Undo revision 145613 by Alextpp (talk): no, it’s “a date” (“one date”) and “multiple data”, `bitSizeOf` is a _unary_ function so only _one_ date can be inspected)
Tag: Undo
Line 1: Line 1:
 
{{LanguageBar}}
 
{{LanguageBar}}
  
The compiler intrinsic function '''<syntaxhighlight lang="pascal" inline>bitSizeOf</syntaxhighlight>''' returns the size of a data in bits.
+
The compiler intrinsic function '''<syntaxhighlight lang="pascal" inline>bitSizeOf</syntaxhighlight>''' returns the size of a date in bits.
  
 
== definition ==
 
== definition ==

Revision as of 12:09, 3 July 2021

Deutsch (de) English (en)

The compiler intrinsic function bitSizeOf returns the size of a date 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.

see also