{$mode delphi}{$H+}
{$R+}
uses
sysutils, ordinalbits;
var a:ShortInt = 0;
HighB: TByteBitIndex = High(TByteBitIndex); B: Byte = 0;
HighSh: TShortIntBitIndex = High(TShortIntBitIndex); Sh: ShortInt = 0;
HighW: TWordBitIndex = High(TWordBitIndex); W: Word = 0;
HighSm: TSmallIntBitIndex = High(TSmallIntBitIndex); Sm: SmallInt = 0;
HighC: TCardinalBitIndex = High(TCardinalBitIndex); C: Cardinal = 0;
HighLI: TIntegerBitIndex = High(TIntegerBitIndex); LI: Integer = 0;
HighNU: TNativeUIntBitIndex = High(TNativeUIntBitIndex);NU: NativeUInt = 0;
HighNI: TNativeIntBitIndex = High(TNativeIntBitIndex); NI: NativeInt = 0;
HighQ: TQwordBitIndex = High(TQwordBitIndex); Q: QWORD = 0;
HighI64: TInt64BitIndex = High(TInt64BitIndex); I64: Int64 = 0;
begin
{$ifdef cpu32}
writeln('Compiled for 32-bit');
{$endif}
{$ifdef cpu64}
writeln('Compiled for 64-bit');
{$endif}
try
write(format('Byte.SetBit(%.2d) : ',[HighB]));
B.SetBit(HighB);
writeln(format('OK: [%s] ',[B.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('ShortInt.SetBit(%.2d) : ',[HighSh]));
Sh.SetBit(HighSh);
writeln(format('OK: [%s] ',[Sh.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('Word.SetBit(%d) : ',[HighW]));
W.SetBit(HighW);
writeln(format('OK: [%s] ',[W.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('SmallInt.SetBit(%d) : ',[HighSm]));
Sm.SetBit(HighSm);
writeln(format('OK: [%s] ',[Sm.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('Cardinal.SetBit(%d) : ',[HighC]));
C.SetBit(HighC);
writeln(format('OK: [%s] ',[C.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('LongInt.SetBit(%d) : ',[HighLI]));
LI.SetBit(HighLI); //LI.SetBit(31) gives compiletime rangecheck error
writeln(format('OK: [%s] ',[LI.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('NativeUint.SetBit(%d): ',[HighNU]));
NU.SetBit(HighNU);
writeln(format('OK: [%s] ',[NU.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('NativeInt.SetBit(%d) : ',[HighNI]));
NI.SetBit(HighNI); //NI.SetBit(31) gives compiletime rangecheck error in 32-bit mode, NI.SetBit(63) is allowed in 64-bit
writeln(format('OK: [%s] ',[NI.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('QWORD.SetBit(%d) : ',[HighQ]));
Q.SetBit(HighQ);
writeln(format('OK: [%s] ',[Q.ToBinString]));
except
on e: exception do writeln(e.message);
end;
try
write(format('Int64.SetBit(%d) : ',[HighI64]));
I64.SetBit(HighI64);
writeln(format('OK: [%s] ',[I64.ToBinString]));
except
on e: exception do writeln(e.message);
end;
end.