Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Unanswered: how to get set of values from a number that is the result of multiple numbers left-sh

    I'm trying to figure out how to get set of values from a number that is the result of multiple numbers left-shifted and added together.

    I have a list of known values as such:

    const VAL1 = 1
    const VAL2 = 2
    const VAL3 = 3
    const VAL4 = 4
    const VAL5 = 5
    const VAL6 = 6

    I'm being provided a number that is the addition of 1 or more left-shifted values. For example, I'm being provided this number:

    98

    How do I go about figuring out which values from my known list represent the 98? In this example, the values would be 2 (VAL2), 5 (VAL5), and 6 (VAL6) (since 1<<2 + 1<<5 + 1<<6 = 98)

  2. #2
    Join Date
    Sep 2002
    Location
    Montreal, Canada
    Posts
    228
    Provided Answers: 1
    Sorry to say but this looks like some school homework... But I'll give you a hint : this is very similar to the change-making problem...

    https://en.wikipedia.org/wiki/Change-making_problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •