<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Hex$
</title>
</head>
<body>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help%3Fen"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;&nbsp;
<a href="../lang%3Fen">Up</a>&nbsp;&nbsp;
<a href="goto%3Fen">Previous</a>&nbsp;&nbsp;
<a href="hour%3Fen">Next</a>&nbsp;&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Hex$
</h1>
<div class="black"><font color="white" size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><u>String</u> <b>= Hex$ (</b> <u>Number</u> AS Long [ <b>,</b> <u>Digits</u> AS Integer ] <b>)</b></pre><p>

Gets the hexadecimal representation of a number.
<p>
If <u>Digits</u> is specified, the representation is padded with unnecessary zeros so that <u>Digits</u> digits are returned.
<p>
<div class="gray"><font color="white" size="-2"><b>Example</b></font></div>
<pre class="example">PRINT Hex$(1972)
<hr>7B4</pre>
<div class="gray"><font color="white" size="-2"><b>Example</b></font></div>
<pre class="example">PRINT Hex$(1972, 8)
<hr>000007B4</pre>
<p>
The sign of a <a href="type/short%3Fen">Short</a> or <a href="type/integer%3Fen">Integer</a> will be extended, because the <u>Number</u> will be extended to <a href="type/long%3Fen">Long</a> .
If the hexadecimal representation should be limited to 16 bits the <a href="and%3Fen">AND</a> operator must be used.
<p>
<div class="gray"><font color="white" size="-2"><b>Example</b></font></div>
<pre class="example">DIM bX AS Byte ' 8 bits unsigned
DIM sX AS Short ' 16 Bits signed

bX = 200
sX = -456
PRINT Hex$(bX), Hex$(sX), Hex$(CLong(sX) AND &hffff&)
<hr>C8	FFFFFFFFFFFFFE38	FE38</pre>
<p>

<hr><b>See also</b><br>
<a href="../cat/format%3Fen">Formatting functions</a>&nbsp;&nbsp;

</div>
<hr>
</body>
</html>

