I was going though this blog and it says

You can represent a list of distinct integers no larger than N using exactly N bits: if the integer i appears in your list, you set the i th bit to true. Bits for which there is no corresponding integers are set to false. For example, the integers 3, 4, 7 can be represented as 00011001. As another example, the integers 1, 2, 7 can be represented as 01100001.

Can someone please explain me how [3, 4, 7] = 00011001 and [1, 2, 7] = 01100001 and also why 8 bits are taken?

  • 1
    Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Dec 10 '13 at 12:49

Think of it as ['0d: OFF', '1st: OFF', '2nd: OFF', '3rd: ON', '4th: ON', '5th: OFF', '6th: OFF', '7th: ON'].

  • Hence the 00011001. – 94239 Dec 10 '13 at 12:35
  • 1
    ohh starting with 0 and counting left to right. Tx a lot! – Aniket Thakur Dec 10 '13 at 12:36
  • 1
    @AniketThakur: as N = 7 you only need 7 bits, the first zero moght be left padding to store it into a byte (8 bits). – Marjan Venema Dec 10 '13 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.