• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] 2^n system

Status
Not open for further replies.
Level 28
Joined
Jan 26, 2007
Messages
4,789
Shouldn't 9 and 10 be '8+1' and '8+2' respectively?

Anyway, it's not that much of a system.
You just have to use a loop (high to low), see if (yourValue) > PowerOf2(loop).
If so, then (yourValue) = (yourValue - PowerOf2(loop)) and you know 1 of the powers.
Continue until (yourValue) == 0, or until the loop hits 0.

Edit: by the way, BonusMod uses this.
You can have a look at that if you want.
 
Status
Not open for further replies.
Top