ACE3/addons/common/functions/fnc_toBin.sqf
Phyma ffaa195fe5 Conform function headers to coding guidelines (#5255)
* Fixed headers to work with silentspike python script

* Fixed rest of the files

* Fixed ace-team
2017-06-08 15:31:51 +02:00

36 lines
648 B
Plaintext

/*
* Author: commy2
* Converts number to binary number
*
* Arguments:
* A number <NUMBER>
*
* Return Value:
* A binary number as string <STRING>
*
* Example:
* [5] call ace_common_fnc_toBin
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_number", ["_minLength", 1]];
private _sign = ["", "-"] select (_number < 0);
_number = round abs _number;
private _bin = ["", "0"] select (_number == 0);
while {_number > 0} do {
private _rest = str (_number mod 2);
_number = floor (_number / 2);
_bin = _rest + _bin;
};
while {count toArray _bin < _minLength} do {
_bin = "0" + _bin;
};
_sign + _bin // return