Reputation: 51
hi i am new in python just started learning with python i got a task in which i need to store "1" byte of integer into different bits just like RGB the value are store in that can any one would write a small program for me and explain that ,please i need a help
Thankyou
Upvotes: 0
Views: 1100
Reputation: 15172
To convert a number to a list of it's binary digits: list(bin(number))[2:]
Upvotes: 0
Reputation: 7864
I'll assume this question is legitimate and appropriate for the forum..
# To Encode:
r = 1
g = 2
b = 3
rgb = r << 16 | g << 8 | b
#To extract:
r = (rgb >> 16) & 0xFF
g = (rgb >> 8) & 0xFF
b = rgb & 0xFF
Upvotes: 2