Qbasicnews.com
April 21, 2018, 02:25:17 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: What the heck is up with BINARY file i/o?  (Read 4824 times)
Zack
*/-\*
*****
Posts: 3974



WWW
« on: April 11, 2007, 07:34:03 PM »

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?
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #1 on: April 11, 2007, 09:19:17 PM »

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.
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #2 on: April 12, 2007, 12:24:57 AM »

Thanks, it works. Funny, I tried that with the c=... line, but I forgot to use c instead in the PUT statement.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!