Rifet Posted January 7, 2020 Report Share Posted January 7, 2020 Lets say I have variable DW150 and DW is 32bit variable so: DW150 = 0000 0000 0000 0000 0000 0000 0000 0000 (is this correct?) How can I store "1" into 4th bit of DW150? Lets say I have variable MB50 = 1 and I want to store value of MB50 into 4th bit of DW150, how can I achieve that? Result after storing should be: DW150 = 0000 1000 0000 0000 0000 0000 0000 0000 Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted January 7, 2020 MVP 2023 Report Share Posted January 7, 2020 You may be able to use the "Toggle Register Bit" function under the "Logic" ladder menu for this purpose. What are you trying to do? Typically in VisiLogic, bit vectors are employed to do this rather than trying to manipulate the bits in an integer register. Link to comment Share on other sites More sharing options...
Isakovic Posted January 8, 2020 Report Share Posted January 8, 2020 Do it elegantly as Flex said or: 1000 0000 0000 0000 0000 0000 0000 in decimal is 134217728. If you store this number in DW150 4th bit (or 28th depends how you count) will be zero. I remember working with older ladder software that didn't have bits manipulation. If you needed to make a certain combination of 1s and 0s in register, first you reset register (store 0), than if bit 1 is 1 add 1, if bit 2 is 1 add 2, if bit 3 is 1 add 4, if bit 4 is 1 add 8.... Good times. Link to comment Share on other sites More sharing options...
Rifet Posted January 8, 2020 Author Report Share Posted January 8, 2020 4 hours ago, Isakovic said: Do it elegantly as Flex said or: 1000 0000 0000 0000 0000 0000 0000 in decimal is 134217728. If you store this number in DW150 4th bit (or 28th depends how you count) will be zero. I remember working with older ladder software that didn't have bits manipulation. If you needed to make a certain combination of 1s and 0s in register, first you reset register (store 0), than if bit 1 is 1 add 1, if bit 2 is 1 add 2, if bit 3 is 1 add 4, if bit 4 is 1 add 8.... Good times. I need bits because I am working with WinCC Flexible 2008 and when I want to configure alarms I need bits, can't use tags, only bits. So I need all my alarms of visilogic to be stored in "Word" in format of 0 and 1 (0000 1000 0010 ... ) Wincc Flexible can only work with bits when configuring alarms, that is problem Link to comment Share on other sites More sharing options...
Rifet Posted January 8, 2020 Author Report Share Posted January 8, 2020 12 hours ago, Flex727 said: You may be able to use the "Toggle Register Bit" function under the "Logic" ladder menu for this purpose. What are you trying to do? Typically in VisiLogic, bit vectors are employed to do this rather than trying to manipulate the bits in an integer register. I need bits because I am working with WinCC Flexible 2008 and when I want to configure alarms I need bits, can't use tags, only bits. So I need all my alarms of visilogic to be stored in "Word" in format of 0 and 1 (0000 1000 0010 ... ) Wincc Flexible can only work with bits when configuring alarms, that is problem Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted January 8, 2020 MVP 2023 Report Share Posted January 8, 2020 MBs are bits. Use them. Link to comment Share on other sites More sharing options...
John_R Posted January 8, 2020 Report Share Posted January 8, 2020 Define an array of MB's say, MB101 through MB132, these are the bit coils that your alarms will trigger. Use the Bit to Num FB (under vectors); A = the starting MB of your array, MB101 B = the DW where you want to store your "bit word", DW1 C = the length of you MB array, const 32 if MB104 is on, then the forth number of the DW will be 1 if MB128 is on, then the 28th number of the DW will be 1 and so on.... Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted January 8, 2020 MVP 2023 Report Share Posted January 8, 2020 Very nice, @John_R! This is the best answer, IMO. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now