Binary conversion in Small Basic

Time to try Small Basic with a binary conversion program.  All seems straightforward, except that I found one annoying quirk with Small Basic – even though I built up the answer string by passing in the 1 and 0 in quotes, which should produce a string result, Small Basic added them as though they were numbers – so “1” + “1” + “1” would produce 3 instead of “111”.

binary code v1

Binary code v1

I ended up with two versions of the code – the first version, keeping things simple by adding strings, used “I” and “O” instead of “1” and “0”, which then produced the desired result.  Again I’ve kept it simple by not putting a loop in, so that the code needs to be run again for each number.

Small Basic itself seemed very straightforward, using the same algorithm as I used in other languages.

display from version 1

Display from version 1

The built in intellisense helps to formulate instructions correctly, it lays the code out neatly so it is easy to follow, and color coding also helps.


binary code version 2

Binary code version 2

The second version, which does output 1s and 0s rather than Is and Os, used the more cumbersome result=Text.Append(result,”1″) to build up the answer string.  This prevented the earlier problem of turning the strings into numbers, but looks more confusing and clumsy.  I wonder what other examples I’ll come across of Small Basic trying to be too helpful and correcting something that it shouldn’t do.

Result display version 2

Result display version 2


About emmyleigh
Writer/editor/proofreader who loves technology

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: