سؤال

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?

هل كانت مفيدة؟

المحلول 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.

نصائح أخرى

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top