Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
var
X: cardinal;
I, J: Byte;
begin
X := 1247433684;
I := PByteArray(PCardinal(@X))[0];
J := PByteArray(PCardinal(@X))[1];
ShowMessage(IntToStr(I) + ' ' + IntToStr(I) );
function IntToBinary(Int: Integer; Digits: Byte): string;
const
CONVERT:array[0..1] of Char = '01';
var
cnt: Integer;
begin
SetLength(Result, Digits);
for cnt := Digits downto 1 do
begin
Result[cnt] := CONVERT[Abs(Int) mod 2];
Int := Int shr 1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
X: cardinal;
I: Byte;
begin
X := 1247433684;
I := PByteArray(PCardinal(@X))[0];
ShowMessage(IntToBinary(I, 8));
end;
function IntToBinary(Int: Integer; Digits: Byte): string;
const
CONVERT:array[0..1] of Char = '01';
var
Cnt: Integer;
begin
SetLength(Result, Digits);
for Cnt := Digits downto 1 do
begin
Result[Cnt] := CONVERT[Abs(Int) mod 2];
Int := Int shr 1;
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
I: Integer;
BArray: array[0..3] of Byte;
Value: Cardinal;
TempStr: string;
begin
Value := 1247433684;
for I := 0 to 3 do
BArray[I] := PByteArray(PCardinal(@Value))[I];
//display
for I := 0 to 3 do
TempStr := TempStr + IntToBinary(BArray[I], 8) + ' - ' + IntToStr(BArray[I]) + #13#10;
ShowMessage(TempStr);
end;
procedure TForm3.Button2Click(Sender: TObject);
var
BArray: array[0..3] of Byte;
Value: Cardinal;
begin
BArray[0] := 212;
BArray[1] := 83;
BArray[2] := 90;
BArray[3] := 74;
Value := PCardinal(PByteArray(@BArray[0]))^;
ShowMessage(IntToStr(Value));
end;
var
X: cardinal;
I, J, K, L: Byte;
begin
X := 1247433524;
for x := 0147433524 to 1247433524 do begin
I := PByteArray(PCardinal(@X))[0];
J := PByteArray(PCardinal(@X))[1];
K := PByteArray(PCardinal(@X))[2];
L := PByteArray(PCardinal(@X))[3];
end;
ShowMessage(IntToBinary(I,8)+#13#10+IntToBinary(J,8)+#13#10+IntToBinary(K,8)+#13#10+IntToBinary(L,8) );
ShowMessage(IntToStr(I)+IntToStr(J)+IntToStr(K)+IntToStr(L) );
ShowMessage(Chr(I)+Chr(J)+Chr(K)+Chr(L) );
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.