I need to convert hex value for 0xc437 To binary like 1100010000110111 and this binary associated with True false For example here ['True','True','False','False' ,'False' and so on And if the value 0x0000, I want to show all False
Asked
Active
Viewed 58 times
-2
-
Does this answer your question? [Convert hex to binary](https://stackoverflow.com/q/1425493/6045800) and [python: convert a list of 1/0s to a list of boolean](https://stackoverflow.com/q/42010942/6045800) – Tomerikoo Aug 16 '21 at 09:05
1 Answers
0
The simplest might be string formatting:
x = 0xc437
[bool(int(c)) for c in f"{x:016b}"]
# [True, True, False, False, False, True, False, False, False, False, True, True, False, True, True, True]
x = 0x0000
[bool(int(c)) for c in f"{x:016b}"]
# [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
f"{x:016b}"
gets you the binary representation of x
padded with leading zeroes to length 16.

user2390182
- 72,016
- 6
- 67
- 89