Hi,

I have a python array that is either a list or numpy array. I want to do a bitwise inversion of all the elements and was wondering what the easiest way would be.

a = [0xFF,0xFF,0xFF,0xFF]
invert to....
b = [0x00,0x00,0x00,0x00]

What is the easiest way to do this?

Thanks!

>>> a = [0xFF,0xFF,0xFF,0xFF]
>>> b = [~val for val in a]
>>> b
[-256, -256, -256, -256]
>>> b = [~val & 0xFF for val in a]
>>> b
[0, 0, 0, 0]
>>> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.