mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
36 lines
586 B
Plaintext
36 lines
586 B
Plaintext
/*
|
|
* Author: commy2
|
|
*
|
|
* Converts number to binary number
|
|
*
|
|
* Arguments:
|
|
* A number
|
|
*
|
|
* Return Value:
|
|
* A binary number, String
|
|
*
|
|
* Public: Yes
|
|
*/
|
|
#include "script_component.hpp"
|
|
|
|
params ["_number", ["_minLength", 1]];
|
|
|
|
private ["_sign", "_bin", "_rest"];
|
|
|
|
_sign = ["", "-"] select (_number < 0);
|
|
|
|
_number = round abs _number;
|
|
_bin = ["", "0"] select (_number == 0);
|
|
|
|
while {_number > 0} do {
|
|
_rest = str (_number mod 2);
|
|
_number = floor (_number / 2);
|
|
_bin = _rest + _bin;
|
|
};
|
|
|
|
while {count toArray _bin < _minLength} do {
|
|
_bin = "0" + _bin;
|
|
};
|
|
|
|
_sign + _bin
|