How to define a terabyte constant in Pascal

1 Answer

0 votes
program TerabyteExample;

{$mode objfpc}{$H+}

{
  Free Pascal typed constants are evaluated at compile time.

  Terabyte sizes:

      1 TiB = 2^40  = 1,099,511,627,776 bytes
      1 TB  = 10^12 = 1,000,000,000,000 bytes

  Both values fit safely inside a QWord (unsigned 64‑bit).
}

const
  // Binary terabyte (tebibyte), using a bit shift.
  // 1 shl 40 = 2^40 bytes.
  TERABYTE_TIB : QWord = QWord(1) shl 40;

  // Decimal terabyte (SI), written as a plain integer literal.
  TERABYTE_TB  : QWord = 1000000000000;

begin
  WriteLn('1 TiB = ', TERABYTE_TIB, ' bytes');
  WriteLn('1 TB  = ', TERABYTE_TB,  ' bytes');
end.



(* 
run:

1 TiB = 1099511627776 bytes
1 TB  = 1000000000000 bytes

*)

 



answered May 3 by avibootz
...