# BASIC 256 - Language Documentation

en:readbyte

## ReadByte

### Format

readbyte
readbyte()
readbyte(filenumber)

### 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

Close, Eof, Open, Openb, ReadByte, Readline, Reset, Write, Writebyte, Writeline, Exists, Seek, Size

en/readbyte.txt · Last modified: 2012/11/01 09:28 by admin