So it's really this line self.DEVICE_REG_DATA &= ~(0x1<<0) that's causing my trouble.
&= bitwise ANDs the value to the left with the value to the right and replaces the value to the left with the result. Ie. It is equivalent to $left = $left & $right;. And the perl code would be exactly the same.
The left value is initialised: self.DEVICE_REG_DATA = 0xff. The right value: ~(0x1<<0) is a stupidly complicated way of writing ~1:
[0] Perl> printf "%b\n", ~(1<<0);; 1111111111111111111111111111111111111111111111111111111111111110 [0] Perl> printf "%b\n", ~(1);; 1111111111111111111111111111111111111111111111111111111111111110 [0] Perl> printf "%b\n", ~1;; 1111111111111111111111111111111111111111111111111111111111111110
(The number of ones may vary depending upon the native size of integers in the version of Python being used.
When ANDed with the initialisation value you get:
printf "%b\n", 0xff & ~1;; 11111110
In other words, the result of the &= statement is to clear the least significant bit of the byte, leaving all the other bits as they were.
Does that help you solve your (unclear) question?
BTW. Early in the post you mention &|, but that doesn't appear anywhere else in your post or code? And isn't a valid Python operator from my (rather awkward) quick search.
In reply to Re: I2C help (from python)
by BrowserUk
in thread I2C help (from python)
by packetstormer
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |