Name

hex — convert an integer to an hexadecimal string

Synopsis

string hex( n,  
  digits);  
int   n;
int   digits ;

Description

Returns the value n as a lower case hexadecimal (base 16) string. If the optional parameter digits is present then the string will be left padded with "0" characters so that it is at least digits in length.

If digits is negative then the result is undefined. It will not be a run time error, and will most likely be the hex representation of the binary data. For example, -256 could become 0xffffff00 on a 32 bit 2's complement system.

Example 36. hex Example

string hexstr = "0x" + hex(127, 4);     // = "0x007f"