Binary read (Language Help)

by zahurdias @, Saturday, August 18, 2012, 11:28 (2559 days ago)

Is it possible to make a binary (or hex) read?

Binary read

by Jim ⌂ @, Russell, KY, Monday, August 20, 2012, 02:46 (2557 days ago) @ zahurdias

No native way but this will work.


file$ = "hexdump.kbs" # replace with your file name
temp$ = "tempfile.txt" # temporary file name

# this statement converts binary file to a hex dump of one byte
# per line
# used LINUX command line hex dump program
# if Windows you will need to find a hex dump program
# and change the command accordingly
system "xxd -p -c 1 " + file$ + " > " + temp$

open temp$
while not eof
#read 2 digit hex number (one byte)
hex$ = read()
print hex$;
end while

#delete temporary file
kill temp$

Binary read

by zombiepigman96, Sunday, August 26, 2012, 16:29 (2551 days ago) @ Jim

I am still learning this language, what does the $ do?

Binary read

by Jim ⌂ @, Russell, KY, Monday, August 27, 2012, 15:41 (2550 days ago) @ zombiepigman96

The $ on the end of the variables temp$, hex$ and file$ tell BASIC256 that these variables contain "string" values and not numeric values. A string is a chunk of text that contains letters, numbers, and special characters.

Binary read

by Gordon, Wednesday, October 17, 2012, 21:56 (2499 days ago) @ Jim

May I suggest adding real binary-safe file handling (preferably before 1.0)?

I am working on a CipherSaber implementation, but the lack of this is a real show-stopper. Moreover, I think that the current state of affairs is kind of inconsistent -- reads can only be performed in "records" (so to speak) whereas writes are not bound by this (yes, I am aware of the corner cases and workarounds, but I figure it is a very bad thing in a primarily educational product).

Having the record-oriented I/O is not necessarily a bad thing, but a bit more consistency there would be preferred (don't know how, though). Having binary I/O is a must IMHO.

Binary read

by Jim ⌂ @, Russell, KY, Thursday, October 18, 2012, 04:58 (2498 days ago) @ Gordon


OK. You asked for it - real work not done :) must play :)

READBYTE, WRITEBYTE and OPENB have been committed to SVN.

b = readbyte(filenum)
writebyte filenum, b
and openb is same as open but binary safe in Windows (does not matter in LINUX)

It is a bit slow but this is BASIC. :) What do you think???


Binary read

by Gordon, Thursday, October 18, 2012, 12:07 (2498 days ago) @ Jim

This also seems to be working well, thank you for the prompt support!

Now... bitwise XOR, please... :) (I'm discovering things needed as I progress :)

Binary read

by Jim ⌂ @, Russell, KY, Thursday, October 18, 2012, 14:16 (2498 days ago) @ Gordon

Try the following...

print xr(0,255)
print xr(1,255)

function xr(p,q)
xr = (p&(~q))|((~p)&q)
end function

XOR is already an operator so you have to call the function something else.

RSS Feed of thread
powered by my little forum