• 🏆 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!
  • ✅ HD Level Design Contest #1 POLL is now OPEN! Check out the stunning visuals of the final entries. 🔗Click here to cast your vote!

[JASS] Integers to Binary Code Script!!!

Status
Not open for further replies.
Level 6
Joined
Aug 15, 2007
Messages
209
The most useless script ever! Nobody uses binary! This trigger makes it so when Player 1 enters a number in chat, it sends a text message containing that number in BINARY!

JASS:
function Trig_Binary_Conversion_Actions takes nothing returns nothing
local string s = GetEventPlayerChatString()
local integer n = S2I(s)
local real init = 1
local string binaryconv = "1"
loop
exitwhen n/init >=1 and n/init < 2
set init = 2 * init
endloop
set n = ModuloInteger(n,R2I(init))
set init = init /2
loop
exitwhen init == .5
    if n/init >= 1 then
    set binaryconv = binaryconv + I2S(1)
    set n = ModuloInteger(n,R2I(init))
    else 
    set binaryconv = binaryconv + I2S(0)
    endif
    set init = init /2
endloop
call DisplayTextToPlayer(Player(0), 0.,0., binaryconv)
endfunction

//===========================================================================
function InitTrig_Binary_Conversion takes nothing returns nothing
    set gg_trg_Binary_Conversion = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Binary_Conversion, Player(0), "", false )
    call TriggerAddAction( gg_trg_Binary_Conversion, function Trig_Binary_Conversion_Actions )
endfunction
 
Level 6
Joined
Aug 15, 2007
Messages
209
Ghost wolf, its the language computers use to represent numbers. It converts them into a string of booleans. It's useless, and I just made this formula because I was bored ^__^. The only possible use I could think of would be to put it in a minigame called "Convert the binary number!" or something.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Ghost wolf, its the language computers use to represent numbers. It converts them into a string of booleans. It's useless, and I just made this formula because I was bored ^__^. The only possible use I could think of would be to put it in a minigame called "Convert the binary number!" or something.

I know whats binary, I asked what Eleandor does with it.
 
Level 11
Joined
Aug 25, 2006
Messages
971
You can store 8 booleans in one extended ascii character!

Though your char-map is undoubtedly much shorter then 255. You can still store 5 booleans with a 32 character char-map.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Most savesystems these days use base 64, with lower case as well as upper case characters. Thus you could display 6 booleans with 1 character, or 1 integer from 0 to 63, or 2 integers from 0 to 7 or 1 integer from 0 to 31 and 1 boolean, ...

My idea was to first convert all data into a bitstream, then convert that bitstream into base64 characters. The code itself would e.g.
reserve the first 20 bits for goldamount, second 10 bits for wood, then 4 bits for a unique hero, then 6 times 8 bits for a unique itemcode. Such a code would mean that you could store up to 1 million gold accuratelly, 1000 wood, 1 hero out of 16 possible heroes, 6 items (possibly 6 times the same one) out of 255 possible itemtypes, in only 14 characters. In addition to this, you could ofcourse compress numbers such as only storing the last 15 bits of your gold which would lower your goldaccuracy by factor 32, while making your code 1 character shorter.
 
Level 6
Joined
Aug 15, 2007
Messages
209
Most savesystems these days use base 64, with lower case as well as upper case characters. Thus you could display 6 booleans with 1 character, or 1 integer from 0 to 63, or 2 integers from 0 to 7 or 1 integer from 0 to 31 and 1 boolean, ...

My idea was to first convert all data into a bitstream, then convert that bitstream into base64 characters. The code itself would e.g.
reserve the first 20 bits for goldamount, second 10 bits for wood, then 4 bits for a unique hero, then 6 times 8 bits for a unique itemcode. Such a code would mean that you could store up to 1 million gold accuratelly, 1000 wood, 1 hero out of 16 possible heroes, 6 items (possibly 6 times the same one) out of 255 possible itemtypes, in only 14 characters. In addition to this, you could ofcourse compress numbers such as only storing the last 15 bits of your gold which would lower your goldaccuracy by factor 32, while making your code 1 character shorter.

That's some srs hax, lol. Do you mind showing me your way of doing it? I see how mine could be made more efficient, but I don't know how different your process is.
 
Level 11
Joined
Aug 25, 2006
Messages
971
How does that have anything to do with 'hacks.'

A bitstream is a line of bits, opposed to grouping bytes. (even though the bitstream will have to be grouped to bytes to save, its more efficient instead of having unused bits)

A bit is 0 or 1
With two bits you can store any number from 0 to 3. With three bits you can store any number from 0 to 7. With four bits you can store any number from 0 to 15.
The storage space calc. (where b is the amount of bits) is (2^b) - 1
I subtract one because the first real number I use is 0. If you wanted to do decimals... go google floating point. If you wanted to do negatives, you use the last bit to represent positive or negative. For example,
You could 101110 is 46, but say you wanted -46 You could put a bit at the end, so would become 0101110 (positive) or 1101110 (negative)

Anyway, your computer stores information like that, except it groups the bits into bytes. (8 bits is stored in one byte)
 
Status
Not open for further replies.
Top