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
answre your own question.

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  
 
 [ 3 post ] 

 Relevant Pages 

1. Converting pascal 6-byte reals to C 8-byte doubles

2. Converting pascal 6-byte reals to C 8-byte doubles

3. Converting Bytes(?) to Int / Int to Bytes

4. easyest method to change bytes order in longint

5. Byte extraction from Longint

6. How convert REAL type stored in six bytes to number

7. how to convert byte to string?

8. converting byte matrix to graphics file

9. how to convert byte to string?

10. Converting TP 6-byte Reals to MSVC doubles...

11. longint to real/real to longint

12. char - byte or byte - char

 

 
Powered by phpBB® Forum Software