Convert 4 bytes to LongInt.
Author Message
Convert 4 bytes to LongInt.

How can I convert 4 bytes representing a number (ie. the first bytes is the
highest byte, the last byte is the lowest byte) to LongInt or Word?

Lets say I have the two bytes 7 and 46, which means;

00000111 and 00101110

...which is 1838.

HOW!? ;-)

Best Regards,
Tore Aursand

Mon, 21 Sep 1998 03:00:00 GMT
Convert 4 bytes to LongInt.

Quote:
>How can I convert 4 bytes representing a number (ie. the first bytes is the
>highest byte, the last byte is the lowest byte) to LongInt or Word?

----------------------------------------------------------------------------

function Bytes2word( x, y: byte ): word;

var
z: word;

begin
z := x;
Bytes2word := Swap( z ) + y
end;

function Words2LongInt( x, y: word ): LongInt;

var
p: record x, y: word end;
q: LongInt absolute p;

begin
p.x := x;
p.y := y;
Words2LongInt := q
end;

function Bytes2LongInt( a, b, c, d: byte ): LongInt;

begin
Bytes2LongInt := Words2LongInt( Bytes2Word( a, b ), Bytes2Word( c, d ) )
end;

--------------------------------------------------------------------------

Grego

--

/------------------------------------------------------------------

Tue, 22 Sep 1998 03:00:00 GMT
Convert 4 bytes to LongInt.

Quote:

>How can I convert 4 bytes representing a number (ie. the first bytes is the
>highest byte, the last byte is the lowest byte) to LongInt or Word?
>Lets say I have the two bytes 7 and 46, which means;
>        00000111 and 00101110
>...which is 1838.
>HOW!? ;-)

Read the file below for a discussion on binary theory, as to why this
is possible.  But simple nuff...

What is 256 * 7 + 46?  Find out where the 256 comes from and you

Quote:
>Best Regards,
>Tore Aursand

Glenn Grotzinger

MOD and S3M user extraordinaire.
Writer of TP tutorial.  All released parts findable at:
ftp://garbo.uwasa.fi/pc/turbopas/tptutr11.zip

Thu, 24 Sep 1998 04:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages