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:

  1. Click Save or Save As in the Small Basic UI
  2. Type in "Welcome" in the Save As window
  3. 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