Jump to content

Recommended Posts

  • MVP 2023
Posted

Num to BIT  i use for  init  some bit vector.

Fast way - Vector copy from XB to MB.  I use power on value for XB and copy this value to MB with one vector copy command.

  • MVP 2023
Posted

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.

  • MVP 2023
Posted
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
  • MVP 2023
Posted

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

  • MVP 2023
Posted

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.

  • MVP 2023
Posted
46 minutes ago, Ausman said:

I haven't tested this, but couldn't you use Toggle Bit in Vector for this?

I wanted to toggle ALL the bits. Toggle Bit in Vector only does one.

  • MVP 2023
Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.