Navigation:  thinBasic Modules > Core > String handling >

HEX$

Previous pageReturn to chapter overviewNext page

 

Description

 

Return a string that is the hexadecimal (base 16) representation of its argument.

 

Syntax

 

s = HEX$(Number [, digits])

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

Number

Numeric

No

The numeric expression to transform into hex notation

Digits

Numeric

Yes

Number of digits to output

 

Remarks

 

Restrictions

 

See also

 

String Handling,

 

Examples

 

Thanks to Abraxas for the following script example

' Usage of the HEX$ Instruction example

' Returns HEX String of a number

 

Dim Base10Num As DWORD VALUE &hAAAA5555

Dim TempVal   As DWORD VALUE Base10Num

Dim n         As Byte  VALUE 0

Dim sMsg      As String

 

sMsg += "Base10 = " & Base10Num & $CRLF 

sMsg += "Binary = " & Bin$(Base10Num, 32) & $CRLF

sMsg += "Hex Nibbles = "

 

' This Groups 4 bits (a nibble) 

For n = 28 To 0 Step -4

  TempVal = Base10Num

  sMsg += " " & HEX$((SHIFT SIGNED RIGHT TempVal, n), 1) ' Shift(n) bits

Next

 

sMsg += $CRLF

sMsg += "Hex = &h" & Hex$(Base10Num, 8)

MSGBOX 0, sMsg ' Display The information

 

 

 

© 2004-2008 thinBasic. All rights reserved. Version 1.7.0.0 Web Site: http://www.thinbasic.com