0

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

5
  • 3
    Can you clarify your question? Is this homework? Commented Sep 14, 2010 at 18:25
  • Perhaps you should start by making sure you understand what these operators do: docs.python.org/library/… Commented Sep 14, 2010 at 18:28
  • 4
    can any one would write a small program for me no Commented Sep 14, 2010 at 18:29
  • Its not a homework its a task and need to understand and explain to other Commented Sep 14, 2010 at 18:41
  • It doesn't matter if it's homework or not. We're not here to write code for you Commented Sep 14, 2010 at 20:25

2 Answers 2

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

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.