Jump to content


Binary number, and checking bits?

2 replies to this topic

#1 RichardMartens OFFLINE  


    Combat Commando

  • 2 posts

Posted Sun Mar 11, 2018 10:33 PM

I have a binary number, how do I check to see if an individual bit in the number is on or off.


And btw, I have the binary numbers in a data array.


for example:

I have



I want to see if the left most bit is a one or a zero,

then I want to check if the next bit is also a one or a zero,

and so on.

So the first two checks would come back as 1s, and the third would tell me it's a zero.


EDIT *****


I may have figured it out, I just have to assine each binary number to a variable the I can check it, for example:

;  Data table 02
 data _Grid_Line01
 %11010000, %00001101, %00000011

 a = _Grid_Line01[0]

 if a{0}=0 then goto __No

Edited by RichardMartens, Sun Mar 11, 2018 10:48 PM.

#2 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 28,538 posts
  • Controlled Randomness
    Replay Value
  • Location:North Carolina (USA)

Posted Mon Mar 12, 2018 1:29 AM

What is supposed to happen when the bits are off or on? Are all bits supposed to be checked because something different happens or does the same thing happen when any bit is on? For example, this does something if any bit is on:


   temp6 = _Grid_Line01[0]
   temp5 = 0
   if temp6{temp5} then goto __Do_Something
   temp5 = temp5 + 1 : if temp5 < 8 then goto __Bit_Check_Loop


This does something different for each bit if it is on:


   temp6 = _Grid_Line01[0]
   if temp6{0} then _Something0 = _Blah_Blah
   if temp6{1} then _Something1 = _Blah_Blah
   if temp6{2} then _Something2 = _Blah_Blah
   if temp6{3} then _Something3 = _Blah_Blah
   if temp6{4} then _Something4 = _Blah_Blah
   if temp6{5} then _Something5 = _Blah_Blah
   if temp6{6} then _Something6 = _Blah_Blah
   if temp6{7} then _Something7 = _Blah_Blah


If you want something to happen for each bit, you can't jump somewhere else (unless it's a gosub) because the other bits won't be checked.


Also remember to check out the Did You Know? box here because you can't use an equal sign with bits:



#3 RichardMartens OFFLINE  


    Combat Commando

  • Topic Starter
  • 2 posts

Posted Mon Mar 12, 2018 8:59 PM

Im just starting out, and have a bad memory, so i sometimes forget formatting and miner rules. But thanks anyways.

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users