0

I'm struggling on converting an apparently easy code from Python to C# as below:

def computeIV(self, lba):
      iv = ""
      lba &= 0xffffffff
      for _ in xrange(4):
          if (lba & 1):
              lba = 0x80000061 ^ (lba >> 1)
          else:
              lba = lba >> 1
          iv += struct.pack("<L", lba)
      return iv

I'm used to C# logic and I really can't understand arrays bitmask ...

1
  • 1
    Regarding this code, C# logic is effectively the same as Python logic. What have you tried already? Commented Aug 25, 2015 at 8:15

1 Answer 1

0

You can make use of BitArray Class in C# which manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).

It offers AND, OR, NOT, SET and XOR functions.

For Shift operation, a possible solution can be found here: BitArray - Shift bits or Shifting a BitArray

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.