# Thread: Calculator and Hex Values

1. Junior Member
Join Date
Mar 2012
Posts
17

## Calculator and Hex Values

Can I use the Calculator in PDI to convert a standard integer to a hexadecimal number?

I've googled and found several people who did this via javascript, but I would prefer to use the Calculator for performance reasons (I have thousands of numbers to convert).

The Calculator has a 'Char to hex encode of string A' function, but it doesn't seem to do what I want. For example, 11 in decimal converts to B in hexadecimal, but the 'Char to hex encode of string A' calculator function returns '002000310031' for an input of 11. So clearly I don't understand the purpose of the 'Char to hex encode of String A' function.

Any other ideas about how to convert integers to hexadecimals using the calculator?

2. Junior Member
Join Date
Mar 2012
Posts
17
Okay, I figured out why '11' becomes '002000310031'. The ASCII text for '11' is start character (002) followed by the ASCII for '1' (which is 31) and then another '1' symbol.

3. Senior Member
Join Date
Nov 2008
Posts
777
You should also be able to convert an integer to hex using the User Defined Java Expression step with the following expression and this type of step has a very high throughput.

Code:
`Integer.toHexString(your_integer_field)`
which "Returns a string representation of the integer argument as an unsigned integer in base 16" if that is what you are looking for.

4. Senior Member
Join Date
Nov 2008
Posts
777
Originally Posted by sandy108
Okay, I figured out why '11' becomes '002000310031'. The ASCII text for '11' is start character (002) followed by the ASCII for '1' (which is 31) and then another '1' symbol.
In your example I think you may actually be getting the result of converting ' 11', i.e., 'space one one'. The ASCII code for the space character is (20). On word boundaries, notice that your result is '0020 0031 0031'.
Last edited by darrell.nelson; 03-27-2012 at 05:42 PM.