Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: Calculator and Hex Values

  1. #1
    Join Date
    Mar 2012
    Posts
    17

    Default 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. #2
    Join Date
    Mar 2012
    Posts
    17

    Default

    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. #3
    Join Date
    Nov 2008
    Posts
    777

    Default

    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.
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

  4. #4
    Join Date
    Nov 2008
    Posts
    777

    Default

    Quote Originally Posted by sandy108 View Post
    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.
    pdi-ce-4.4.0-stable
    Java 1.7 (64 bit)
    MySQL 5.6 (64 bit)
    Windows 7 (64 bit)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.