2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
/*
|
2015-09-17 16:25:02 +00:00
|
|
|
* Author: commy2
|
|
|
|
* Converts number to binary number
|
|
|
|
*
|
|
|
|
* Arguments:
|
2023-04-30 21:03:35 +00:00
|
|
|
* 0: A number <NUMBER>
|
|
|
|
* 1: Minumum length of numbers <NUMBER> (default: 1)
|
2015-09-17 16:25:02 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-09-19 22:55:58 +00:00
|
|
|
* A binary number as string <STRING>
|
2015-09-17 16:25:02 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [5] call ace_common_fnc_toBin
|
|
|
|
*
|
2015-09-17 16:25:02 +00:00
|
|
|
* Public: Yes
|
|
|
|
*/
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-09-17 16:25:02 +00:00
|
|
|
params ["_number", ["_minLength", 1]];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-12-14 12:08:19 +00:00
|
|
|
private _sign = ["", "-"] select (_number < 0);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_number = round abs _number;
|
2015-12-14 12:08:19 +00:00
|
|
|
private _bin = ["", "0"] select (_number == 0);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
while {_number > 0} do {
|
2015-12-14 12:08:19 +00:00
|
|
|
private _rest = str (_number mod 2);
|
2015-05-14 18:06:06 +00:00
|
|
|
_number = floor (_number / 2);
|
|
|
|
_bin = _rest + _bin;
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
while {count toArray _bin < _minLength} do {
|
2015-05-14 18:06:06 +00:00
|
|
|
_bin = "0" + _bin;
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2015-09-19 22:55:58 +00:00
|
|
|
_sign + _bin // return
|