Small Basic: Text Files and Binary Files
Text Files and Binary Files
To understand the difference between text files and binary files, let’s try out a basic program that says, "Welcome to Small Basic." You'll save your code as Welcome.sb and, when you run the program, Small Basic creates Welcome.exe (plus other files).
First, write out this program (or copy/paste it into Small Basic):
TextWindow.WriteLine("Welcome to Small Basic")
Second, save your program:
- Click Save or Save As in the Small Basic UI
- Type in "Welcome" in the Save As window
- Click Save
Let’s use Notepad to open both files and see what they contain. The following figure shows how both files appear in Notepad.
Although both files are made up of long sequences of 1s and 0s, the interpretation of these 1s and 0s is what makes the difference between text files and binary files. To explain, let’s say that you want to store the number 26327 in a file. One way is to save the ASCII code for each of the five digits in the number. The result is 00110010 00110110 00110011 00110010 00110100.
Another way is to save the binary representation of the number which is 0110011011010111. As this simple example shows, saving the data in binary form is more efficient in terms of space (it takes less space to save the same data).
Do you have any questions? Ask us! We're full of answers and other fine things!
Head to the Small Basic forum to get the most answers to your questions:
https://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads/
And go to https://blogs.msdn.com/SmallBasic to download Small Basic and learn all about it!
Small and Basically yours,
- Ninja Ed & Majed Marji
Comments
Anonymous
August 15, 2015
Nice explanation. Back in the day, one could open a binary file and make small changes. If you want to get more information tools like PE Explorer get more information out of a binary.Anonymous
August 22, 2015
Ha! Yes, the good old days! Thanks, Sean!Anonymous
January 30, 2016
Computers Today (part 1 of 6) blogs.msdn.com/.../computers-today.aspx .... CS SPOTLIGHT: Girls in computer programming... why it matters!!! blogs.msdn.com/.../cs-spotlight-girls-in-computer-programming-why-it-matters.aspx