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
2 Answers 2
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
Sign up to request clarification or add additional context in comments.
Comments
To convert a number to a list of it's binary digits: list(bin(number))[2:]
answered Sep 15, 2010 at 10:56
dheerosaur
15.3k6 gold badges33 silver badges31 bronze badges
Comments
lang-py
can any one would write a small program for meno