gmlscripts

dec_to_hex

Apr 21st, 2020
1,095
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @func   dec_to_hex(dec [, digits])
  2. ///
  3. /// @desc   Returns a string of hexadecimal digits.
  4. ///         Hexadecimal strings are padded to an
  5. ///         optional number of digits.
  6. ///
  7. /// @arg    {real}      dec         non-negative integer
  8. /// @arg    {real}      digits      minimum number of digits
  9. ///
  10. /// @return {string}    hexadecimal
  11. ///
  12. /// GMLscripts.com/license
  13. {
  14.     var dec = argument[0],
  15.         dig = (argument_count > 1) ? argument[1] : 1,
  16.         hex = "",
  17.         h = "0123456789ABCDEF";
  18.        
  19.     while (dig-- || dec) {
  20.         hex = string_char_at(h, (dec & $F) + 1) + hex;
  21.         dec = dec >> 4;
  22.     }
  23.    
  24.     return hex;
  25. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×