• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Multiple integers stored into one

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
ok this is really hard to explain but most coders would know exactly what im talking about.

12^6 = 2985984

using the modulo function, how can i subtract numbers so i can do like

n%12 = 10
(n/12)%12 = 11
(n/144)%12 = 3
(n/(12^3))%12 = 7

and so on
 
Level 4
Joined
Jan 27, 2010
Messages
133
I REAAAALY should do this in Windows... but, whatev ^^

JASS:
// stores numbers in range (0,11)

function Store takes integer n0, n1, n2, n3, n4, n5 returns integer
    return n0 + 12*n1 + 144*n2 + 144*12*n3 +144*144*n4 + 144*144*12*n5
endfunction

function RetrieveN takes integer packed, integer n returns integer
    local integer count=0
    local integer mod
    loop
        set mod = ModuloInteger(packed,12)
        if count==n then
            return mod
        endif
        set packed = (packed - mod)/12
        set count=count+1
    endloop
endfunction

JASS:
integer multiple = Store(1,7,2,0,0,0)
RetrieveN(multiple,0) // n0 == 1
RetrieveN(multiple,1) // n1 == 7
RetrieveN(multiple,2) // n2 == 2
RetrieveN(multiple,3) // n3 == 0
RetrieveN(multiple,4) // n4 == 0
RetrieveN(multiple,5) // n5 == 0
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
If the max is 12^6, then

number - number/12^6*12^6 = stored number
number/12^6 = remaining numbers (removing the stored number)

:p

I REAAAALY should do this in Windows... but, whatev ^^

JASS:
// stores numbers in range (0,11)

function Store takes integer n0, n1, n2, n3, n4, n5 returns integer
    return n0 + 12*n1 + 144*n2 + 144*12*n3 +144*144*n4 + 144*144*12*n5
endfunction

function RetrieveN takes integer packed, integer n returns integer
    local integer count=0
    local integer mod
    loop
        set mod = ModuloInteger(packed,12)
        if count==n then
            return mod
        endif
        set packed = (packed - mod)/12
        set count=count+1
    endloop
endfunction

Didnt think of doing it that way. Thanks
 
Status
Not open for further replies.
Top