Jump to content
The simFlight Network Forums

Single bits in LUA


Recommended Posts

Hi,

I need a little help with LUA (once again).

I do perfectly understand how to read and write bytes, words, etc in LUA, but I need to change single bits now.

Tried to find any info on that in the forum, but didn't find anything.

So, how can I read and write values of bits in LUA?

please help

Potroh

Link to comment
Share on other sites

So, how can I read and write values of bits in LUA?

At present you have to read the byte or word or whatever, then use the Logic library facilities or And, Or, Xor to clear, set or toggle the bit(s), and write the changed value back. So, for example:

x = ipc.readUB(0x1234) -- read byte to change

x = logic.And(x, 254) -- clear bit 0 (worth 1, 255-1 = 254)

ipc.writeUB(0x1234, x)

or, the same more efficiently (and safer, avoiding possible other changes to the same offset by others between the read and write):

ipc.writeUB(0x1234, logic.And( ipc.readUB(0x1234), 254))

These sorts of operations can become quite frequent, though, and I am considering adding "SetBits", "ClearBits" and "ToggleBits" functions to the ipc library. Maybe soon ...

Regards

Pete

Link to comment
Share on other sites

These sorts of operations can become quite frequent, though, and I am considering adding "SetBits", "ClearBits" and "ToggleBits" functions to the ipc library. Maybe soon ...

Hi Pete,

Many thanks for the info (the lesson rather). Starts to be clearer now, but 'Setbits, etc. function would truly solve a lot of problems for me - and hopefully others too.

Please think of it when got the time...

best regards

Potroh

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.

Guest
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.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.