Jump to content

Recommended Posts

  • MVP 2023

No, I need to TOGGLE each bit in the vector. Some of the bits are on and some are off. I need to flip each bit. It doesn't have to be immediate, just in a single scan. I can brute force it by copying each bit to another vector with an inverted contact and coil (x25), requiring 4 rungs, perhaps fewer, but I was just looking for a clever way to do it without all that typing.

Or maybe I'm misunderstanding what you're suggesting.

I'm thinking I can convert the vector to an integer, multiply by -1, then subtract 1, then convert back to a bit vector. I'll see if that works.

Link to comment
Share on other sites

  • MVP 2023
22 minutes ago, Flex727 said:

I'm thinking I can convert the vector to an integer, multiply by -1, then subtract 1, then convert back to a bit vector. I'll see if that works.

This works perfectly. I think I learned this in middle school math and totally forgot.

  • Thanks 1
Link to comment
Share on other sites

  • MVP 2023

Maybe I didn't understand the task at first and thought that you need to quickly turn the bits off or on. I liked your idea with the math.

However, there was an idea in my head that the function could be done differently.

The result is in this piece of code

toggle1.jpg.47d950107e16bb9c11d02e43119c33db.jpg

I will also add a test project for those who want to try to do this action in another way.

TOGGLE.vlp

Link to comment
Share on other sites

  • MVP 2023

I like your method, kratmel! Here's what I ended up doing:

image.png.ead2ac9112e3fe1bed24c43c3e4c51fd.png

The original bit was an "enabled" bit that I needed to use to hide an HMI element, so it needed to be flipped. Normally that's not a problem, but when you have 25 of them it's a pain. I have begged Unitronics for a checkbox on the HMI element hide setting to allow either on or off to hide the element, but I'm sure we'll never see it.

Link to comment
Share on other sites

  • MVP 2023

Ahh yes, sorry.  I've used it within Vectors in the past and mis-remembered  that it allowed a range to be done. 

I'm putting a trademark on mis-remembered.  But I'll allow usage here on the forum.  We can make it the person over 40s version of "mybad", which unfortunately covers a host of frustrating actions that have little responsibility attached.  🙂

cheers, Aus

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.

×
×
  • Create New...