# [JASS]Integers to Binary Code Script!!!

Status
Not open for further replies.

#### Jetherit

Level 6
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``````

#### GhostWolf

Level 29
Great !!! ... what do you want

#### Eleandor

Level 21
I use binary..

Although I use another method to convert it... One that might be faster, don't know that...

#### GhostWolf

Level 29
Just from interest, what do you use binary with ? (I mean... why do you need it )

#### Jetherit

Level 6
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.

#### GhostWolf

Level 29
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.

#### Eleandor

Level 21
If you need to know, I used it to make my personal save/load code shorter...

#### wd40bomber7

Level 11
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.

#### Eleandor

Level 21
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.

#### Jetherit

Level 6
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.

#### wd40bomber7

Level 11
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.

[Solved] Whats Wrong?
Replies
3
Views
544
Replies
2
Views
829
[JASS] MUI Timer
Replies
3
Views
941
Replies
2
Views
591
Replies
14
Views
1K