Timeline for answer to Python: Extracting bits from a byte by Zaur Nasibov
Current License: CC BY-SA 4.0
Post Revisions
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 5, 2022 at 9:15 | comment | added | Wolf |
print('First bit is set') – the word first is very confusing here.
|
|
| Jul 25, 2018 at 15:29 | history | edited | Zaur Nasibov | CC BY-SA 4.0 |
Updated to "implicit" if and added bit-shifting version
|
| S Nov 18, 2016 at 19:29 | history | suggested | Kieran | CC BY-SA 3.0 |
Converted pseudocode to python for consistency
|
| Nov 18, 2016 at 17:56 | review | Suggested edits | |||
| S Nov 18, 2016 at 19:29 | |||||
| Mar 30, 2012 at 15:25 | comment | added | Zaur Nasibov | Consider this: bin(178) == 10110010; If I uderstood correctly, you need to return all bytes starting from i.e. 5th byte. Then 178 & (2^5 - 1), should do the trick, because in this case 10110010 & 00011111 =わ=わ 00010010 | |
| Mar 30, 2012 at 15:23 | comment | added | D.Shawley |
Explicit is better than implicit so x & 0b10 != 0 is fine by me
|
|
| Mar 30, 2012 at 15:22 | comment | added | Sven Marnach |
!= 0 is not quite as bad as == True, but it is close. :)
|
|
| Mar 30, 2012 at 15:21 | comment | added | tom10 |
+1: but one doesn't need the !=0 part, if x&0b10 should be sufficient.
|
|
| Mar 30, 2012 at 15:18 | comment | added | Evan Borgstrom | Thanks, but that doesn't really answer my question. Given byte = 178, how would you extract flag == 1 & numbytes == 50? | |
| Mar 30, 2012 at 15:16 | history | answered | Zaur Nasibov | CC BY-SA 3.0 |