Search code examples
labview

Bitwise negation up to the first positive bit


I was working in a project and I can´t use the bitwise negation with a U32 bits (Unsigned 32 bits) because when I tried to use the negation operator for example I have 1 and the negation (according to this function) was the biggest number possible with U32 and I expected the zero. My idea was working with a binary number like (110010) and I need to only negate the bits after the first 1-bit(001101). There is a way to do that in LabVIEW?


Solution

  • This computes the value you are looking for.

    • 1110 --> 0001 (aka, 1)
    • 1010 --> 0101 (aka, 101)
    • 111 --> 000 (aka, 0) [indeed, all patterns that are all "1" will become 0]
    • 0 --> 0 [because there are no bits to negate... maybe you want to special case this as "1"?)

    Note: This is a VI Snippet. Save the .png file to your disk then drag the image from your OS into LabVIEW and it will generate the block diagram (I wrote it in LV 2016, so it works for 2016 or later). Sometimes dragging directly from browser to diagram works, but most browsers seem to strip out the EXIF data that makes that work.

    enter image description here