Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tough one

Status
Not open for further replies.

lordhuh

Programmer
Apr 25, 2000
96
US
i am curently for the heck of it. wanting to see exactly what is written in a file. is there a way. to read/write 1' s and 0's. also i want to be able to view the 1's and 0's. (not for malicous perposes if thats what you think it is). i have been experimenting with binary format but that is not really getting me what i want. well it may be but i want to be able to view the file in all the wonders of indecipherable computer language. and then write it back again. i dont want an exact answer for this. i want someone to point me in the right direction, give me some tips, anything like that. thanks Karl Pietri
lordhuh.pota.to

 
If I read your post correctly, all you need to do is convert each character that you write out to file into its binary version of its ASCII code.
If you are to do this, first decide how many digits your binary numbers will have (255 will be 11111111 - eight ones) and then creat a function to convert a character string to binary code and write this out to file.
Also, create the opposite function to convert the binary code back to a character string for reading from the file, so that you can view the string normally in your program, but the string will be "encoded" in the file.

Simon
 
Hi Karl,

If you want view the contents of a file in a meaningful way you may want to consider displaying it in hexadecimal format. All of the decent "binary" file viewers/editors I've seen do it that way: a column of six-digit hexadecimal addresses followed by sixteen columns of hexadecimal values followed by the actual characters found in each of the 16-byte paragraphs. You could always include an option to display in binary (if you are willing to squint that hard).

One way to do this would be to set up a grid with 16 colums and 16 rows. Create a file buffer (a fixed length string) 256 bytes long, open a file in Binary mode and use the Get statement to read the first 256 bytes of the file.

Set up two nested For/Next loops, each to repeat 16 times. (This would be a lot easier to express with code but since you seem to be a do-it-yourself kind of guy, I'll let your own skills lead you to a solution).

Inside the first loop, initialize an empty string. You will use it to populate each row of the grid. Inside the second loop we'll go through the current 16-byte paragraph, getting the value of each byte, converting it to a two-byte hexadecimal string and concatenating it with the first string. Use something like:[tt]
First$ = First$ & Hex$(Asc(Mid$(GotFromFile$,CurrentPos,1))) & VbTab[/tt]

(The VbTab will help populate an entire grid row. You'll have to increment CurrentPos every time you get a byte.)

Repeat that 16 times for each of 16 grid rows, clearing the first string inside the first loop. You might also want to include the actual characters in the paragraph in another 16 columns to the right. And a hex address to the left (it will keep you from getting lost when you start navigating the Windows swap file). ;-)

Good luck. This could turn into a challenging project for you.


VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top