LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

16 Bits

Root / Programming Questions / [.]

h267Created:
How should I represent 16 bits of data in SmileBASIC? Do I use ASCII or an array? If I had a value lower than 256 in an array slot, would it count as 8 bits or inflate? Same with having either a 0 or 1 in an array slot. Will this count as only one bit? (I'm trying to make my files as tiny as possible. You'll see why soon. ;] )
SpoilerBEES

Integer variables are always 32 bits, and characters in strings are always 16 (except they can be between 8 and 24 bits when saved) Strings are way too slow to store data efficiently, though. You could store two 16 bit values in an integer by doing something like:
INTEGER=V1 OR (V2<<16)

V1=INTEGER AND &HFFFF
V2=INTEGER>>16

12Me21's code will have the odd property of extending the 'sign' bit of the V2 value, but not the V1 value, when they are 'extracted' from INTEGER.

12Me21's code will have the odd property of extending the 'sign' bit of the V2 value, but not the V1 value, when they are 'extracted' from INTEGER.
Right shifts in SB are "arithmetic", they carry the sign bit. You should always shift first, mask later, so you avoid weirdness like that.

How do I turn a variable into binary?

How do I turn a variable into binary?
Turn it into a bitstring with BIN$?

How do I turn a variable into binary?
VAR BINARY
BINARY = 1
BINARY = 0
WHILE TRUE
 IF BINARY > 1 THEN BINARY = 1
 IF BINARY < 0 THEN BINARY = 0
WEND
Just one?