mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Optimize ace_common_fnc_toHex
This commit is contained in:
@ -258,6 +258,9 @@ if (hasInterface) then {
|
|||||||
}, 0, []] call cba_fnc_addPerFrameHandler;
|
}, 0, []] call cba_fnc_addPerFrameHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Init toHex
|
||||||
|
[0] call FUNC(toHex);
|
||||||
|
|
||||||
ADDON = true;
|
ADDON = true;
|
||||||
|
|
||||||
isHC = !(hasInterface || isDedicated);
|
isHC = !(hasInterface || isDedicated);
|
||||||
|
@ -1,47 +1,48 @@
|
|||||||
/*
|
/*
|
||||||
Author: commy2
|
Author: commy2, CAA-Picard
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Converts number to hexadecimal number
|
Converts number to hexadecimal number
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
A number
|
A number between 0 and 255 <NUMBER>
|
||||||
|
|
||||||
Return Value:
|
Return Value:
|
||||||
A hexadecimal number, String
|
A hexadecimal number, String
|
||||||
*/
|
*/
|
||||||
#include "script_component.hpp"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
private ["_number", "_minLength", "_sign", "_hex", "_rest"];
|
private ["_number"];
|
||||||
|
_number = ((round abs (_this select 0)) max 0) min 255;
|
||||||
|
|
||||||
_number = _this select 0;
|
if (isNil QGVAR(hexArray)) then {
|
||||||
_minLength = _this select 1;
|
private ["_minLength", "_i", "_num", "_hex", "_rest"];
|
||||||
|
|
||||||
if (isNil "_minLength") then {_minLength = 1};
|
GVAR(hexArray) = [];
|
||||||
|
_minLength = 2;
|
||||||
|
for [{_i = 0;}, {_i < 256}, {_i = _i + 1}] do {
|
||||||
|
_num = _i;
|
||||||
|
_hex = ["", "0"] select (_i == 0);
|
||||||
|
|
||||||
_sign = ["", "-"] select (_number < 0);
|
while {_num > 0} do {
|
||||||
|
_rest = _num mod 16;
|
||||||
_number = round abs _number;
|
_rest = switch _rest do {
|
||||||
_hex = ["", "0"] select (_number == 0);
|
case 10 : {"A"};
|
||||||
|
case 11 : {"B"};
|
||||||
while {_number > 0} do {
|
case 12 : {"C"};
|
||||||
_rest = _number mod 16;
|
case 13 : {"D"};
|
||||||
_rest = switch _rest do {
|
case 14 : {"E"};
|
||||||
case 10 : {"A"};
|
case 15 : {"F"};
|
||||||
case 11 : {"B"};
|
default {str _rest};
|
||||||
case 12 : {"C"};
|
};
|
||||||
case 13 : {"D"};
|
_num = floor (_num / 16);
|
||||||
case 14 : {"E"};
|
_hex = _rest + _hex;
|
||||||
case 15 : {"F"};
|
};
|
||||||
default {str _rest};
|
while {count toArray _hex < _minLength} do {
|
||||||
};
|
_hex = "0" + _hex;
|
||||||
_number = floor (_number / 16);
|
};
|
||||||
|
GVAR(hexArray) pushBack _hex;
|
||||||
_hex = _rest + _hex;
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
while {count toArray _hex < _minLength} do {
|
(GVAR(hexArray) select _number)
|
||||||
_hex = "0" + _hex;
|
|
||||||
};
|
|
||||||
|
|
||||||
_sign + _hex
|
|
||||||
|
Reference in New Issue
Block a user