Question

With the following

DIM a AS INTEGER
a = 10
OPEN "myFile" FOR BINARY AS #1
PUT #1, 1, a
CLOSE #1

I get a file (myFile) with two bytes (using QB64). The first byte is indeed 0A, but there is a second byte 00.

How can I create a file with just one byte?

Was it helpful?

Solution 2

Try this

DIM a AS _UNSIGNED _BYTE
a = 10
OPEN "myFile" FOR BINARY AS #1
PUT #1, 1, a
CLOSE #1

It seems like INTEGER is 2 bytes.

OTHER TIPS

Snip to write a byte to file:

DIM B AS STRING * 1
x = 10
B = CHR$(x)
OPEN "myfile" FOR BINARY AS #1
PUT #1, 1, B
CLOSE #1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top