Jump to content

Binary number, and checking bits?


Recommended Posts

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
Link to comment
Share on other sites

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:



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...