2015-01-11 16:42:31 +00:00
|
|
|
/*
|
2015-09-17 16:25:02 +00:00
|
|
|
* Author: commy2
|
|
|
|
*
|
|
|
|
* Converts number to binary number
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* A number
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* A binary number, String
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
2015-01-13 19:56:02 +00:00
|
|
|
#include "script_component.hpp"
|
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-09-17 16:25:02 +00:00
|
|
|
private ["_sign", "_bin", "_rest"];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_sign = ["", "-"] select (_number < 0);
|
|
|
|
|
|
|
|
_number = round abs _number;
|
|
|
|
_bin = ["", "0"] select (_number == 0);
|
|
|
|
|
|
|
|
while {_number > 0} do {
|
2015-05-14 18:06:06 +00:00
|
|
|
_rest = str (_number mod 2);
|
|
|
|
_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
|
|
|
};
|
|
|
|
|
|
|
|
_sign + _bin
|