0-255 number to byte output

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

0-255 number to byte output

Post by Provoni »

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
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: 0-255 number to byte output

Post by fxm »

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: 514
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: 0-255 number to byte output

Post by Provoni »

Great, thanks fxm.
Post Reply