0-255 number to byte output

New to FreeBASIC? Post your questions here.
Provoni
Posts: 386
Joined: Jan 05, 2014 12:33
Location: Belgium

0-255 number to byte output

Postby Provoni » Dec 03, 2019 12:25

Hey all,

I want to store numbers between 0 and 255 in a file such that each number is 1 byte but don't know how to do this.

Thanks

dim as integer i
open "test.txt" for output as #1
for i=1 to 100
print #1,str(rnd*256)) 'this will output a number in text rather than it being 1 byte...
next i
close #1
fxm
Posts: 9939
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: 0-255 number to byte output

Postby fxm » Dec 03, 2019 12:50

For example:

Code: Select all

#include "file.bi"

dim as integer i
open "test.dat" for binary access write as #1
for i = 1 to 100
put #1, , cubyte(int(rnd * 256))
next i
close #1

print filelen("test.dat")

sleep
Provoni
Posts: 386
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: 0-255 number to byte output

Postby Provoni » Dec 03, 2019 12:59

Great, thanks fxm.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests