Convert String of Digits to Hexadecimal

CodeWright® - API Macro - Royalty Free - 2005.01.01 17:15
Send Comments


Convert String of Digits to Hexadecimal.

This function is an augmentation of NumsToHex that attempts to correct these limitation.


Starbase distributes the the API macro NumsToHex with each copy of CodeWright. This function is quite interesting and can be helpful when converting from decimal to hexadecimal.

Unfortunately NumsToHex does not check for either overflow or underflow conditions. Consequently, the results of the conversions can be incorrect. This being the case, it would seem foolhardy to rely on NumsToHex for any conversion.

tlaStrToHex leverages the code in NumsToHex and validates the results. All underflow conditions are eliminated and all overflow conditions are identified. A comparison of the two functions is:


Non Boundary
Input 4095
Output NumsToHex 0xfff
tlaStrToHex 0xfff
Non Boundary
Input -4095
Output NumsToHex -0xfff
Input 00000015
Output NumsToHex 0x0
Input 4294967295
Output NumsToHex 0xffffffff
Input 4294967296
Output NumsToHex 0x0
Input 4294967297
Output NumsToHex 0x1
Input 9999999999
Output NumsToHex 0x540be3ff


tlaStrToHex( )

Input Parameters


Return Codes

Code Message
strings tlaStrToHex: strings string(s) converted to hex.
-1 tlaStrToHex: strings string(s) converted to hex with errors overflow error(s).
-1 tlaStrToHex: Column selection is not supported.
-1 tlaStrToHex: "Current buffer is read-only.


This function calls tlaError.


Current version verified under:

  • CodeWright 7.0b
  • CodeWright 7.0c
  • CodeWright 7.5.1
  • CodeWright 7.5.2
  • CodeWright for .NET 7.0

CodeWright for .NET Restriction



There are three primary methods for installing this macro on your system. Method A uses the tlaMDE tool available for purchase from this website. Method B manipulates the macro repository directly. Method C uses the API Macro... tool provided in every copy of CodeWright (but not CodeWright for .NET).

Method A - tlaMDE - CodeWright or CodeWright for .NET

  • Select the Code button on this page.
  • When the second window opens, select all the text in the text box.
  • Issue Ctl-C (copy).
  • Create a new file in CodeWright or CodeWright for .NET.
  • Issue Ctl-V (paste).
  • Issue tlaMDE C (save and compile).

Method B - Copy to Repository - CodeWright or CodeWright for .NET

  • Select the Code button on this page.
  • When the second window opens, select all the text in the text box for a macro.
  • Issue Ctl-C (copy).
  • Load the macro repository "cwright.mac" from your CodeWright or CodeWright for .NET root:
  • issue Ctl-End to go to the end of file.
  • Issue Ctl-V (paste).
  • Close the file and respond yes to the write request.

Method C - API Macro ... - CodeWright Only

  • Select the Code button on this page.
  • When the second window opens, select text from the text box for a macro:
    • Do not select the [API Macro ... header line.
    • Select all other lines in the macro.
  • Issue Ctl-C (copy).
  • Open the CodeWright Tools | API Macros... dialog.
  • Press the New button.
  • Select the Edit box.
  • Issue Ctl-V (paste).
  • Double-click on the function name in the header of the macro.
  • Issue Ctl-C (copy).
  • Select the Name box.
  • Issue Ctl-V (paste).
  • Delete the trailing blank from the name.
  • Select the Save button.
  • Select the Close button.
  • Repeat this process for each macro in the text box.


tlaTools is a Dynamic Link Library that contains most of the API macros on this website in a single easy to install package. The tlaTools DLL can be purchased by selecting the Buy button on this page.

tlaStrToHex is included as a function in tlaTools.

Copyright © 1993-2005 Thom Little Associates, Ltd. revised 2005.01.01 17:15
One Central Square, Keene, NH 03431-3787 phone 603-357-7567