tags:

views:

89

answers:

2

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  A: 

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
Rakis
Thank you very much its will really help me thank again
Nomaan
A: 

To convert a number to a list of it's binary digits: list(bin(number))[2:]

dheerosaur