en:readbyte

ReadByte (Function)

Format

readbyte
readbyte ( )
readbyte ( file_number )

returns positive_integer_value

Description

Reads and returns the next byte (8 bits) as a number 0-255 from an open file. If the file number is not specified file number zero (0) will be used.
File should be opened with the Openb statement so that ASCII CR/LF translation does not happen.

Example

cls
f$ = "binary.dat"
print "new file"
openb f$
reset
for t = 1 to 20
   n = r()
   print n+" ";
   writebyte n
next t
print
close
print "open and read"
openb f$
while not eof
   print readbyte()+" ";
end while
print
print "position to 10 and read"
seek 10
while not eof
   print readbyte()+" ";
end while
print
close
end
function r()
   r = int(rand*256)
end function

will display something like

new file
181 163 155 23 46 93 122 212 178 225 1 62 113 130 202 52 185 51 37 165
open and read
181 163 155 23 46 93 122 212 178 225 1 62 113 130 202 52 185 51 37 165
position to 10 and read
1 62 113 130 202 52 185 51 37 165 

See Also

History

en/readbyte.txt · Last modified: 2014/02/08 22:37 by admin