WriteInt stream,int
Parameters
|
stream - a file stream opened for writing, or a TCP stream int - integer value to write (-2147483648 to 2147483647) |
Description
|
Writes a 32-bit integer to a file or stream. An int occupies 4 bytes, stored least significant byte first, and keeps its full range and sign - the workhorse for binary save data. A float passed in is converted to an integer first, so the fractional part is lost; use WriteFloat when that matters. Read it back with ReadInt, in the same order it was written - a binary file format is really just an agreed sequence of writes and matching reads. See also: ReadInt, WriteShort, WriteFloat, WriteString. |
Example
; WriteInt Example ; ---------------- ; WriteInt stores a 4-byte integer (-2147483648 to 2147483647) file=WriteFile("demo_ints.dat") WriteInt file,10 WriteInt file,-365 WriteInt file,2147483647 CloseFile file Print "Wrote 3 integers - demo_ints.dat is "+FileSize("demo_ints.dat")+" bytes (3 x 4)" ; Read them back to prove the round trip file=ReadFile("demo_ints.dat") a=ReadInt(file) b=ReadInt(file) c=ReadInt(file) CloseFile file Print "Read back: "+a+", "+b+", "+c ; Clean up the demo file DeleteFile "demo_ints.dat" Print "Deleted demo_ints.dat" Print "" Print "Press any key to close the example" WaitKey End
Index