Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What the heck is up with BINARY file i/o?
#1
I want to make a program, very basic, that will XOR the first byte in a file with a code, and replace that byte with the new character.
Code:
dim as string infile
input "infile: ",infile
dim as ubyte code
input "code:",code
open infile for binary as #1
dim as ubyte temp,c
get #1,1,temp
c=temp xor code
put #1,1,temp xor code
close #1
It simply doesn't work. It ruins the file, adding extra characters and changing the size of the file. Any insight?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#2
The expression 'temp xor code' that you are using in the PUT statement is evaluated in a full 32-bit integer. Cast to a UByte or do it in a temporary variable to get the right results.
Reply
#3
Thanks, it works. Funny, I tried that with the c=... line, but I forgot to use c instead in the PUT statement.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)