Converting Strings to hex

Hello Everyone:
I'm trying to connect to a local system which needs byte streams... Then I use byte arrays as follows:
final byte[] LOGIN = {(byte)0x31, (byte)0x36, (byte)0x37, (byte)0x38}};
In Ascii Code it means "1678".
I have no problem with this, the real problem is that I need to transform a String entered by the app. user into bytes (the Ascii code), I tried to cast the chars with <<(byte)'c'>>, but it doesn't work.
What I should do?
Thanks.
Jogom

I have no problem with this, the real problem is that
I need to transform a String entered by the app. user
into bytes (the Ascii code), I tried to cast the chars
with <<(byte)'c'>>, but it doesn't work.(byte) 'c' works for me. I get a byte value of 99, which is exactly what I expect. How does it not work for you?

Similar Messages

  • Problem in Converting String (containing arabic) to HEX

    Hi,
    I am trying to convert Arabic Text stored in a String into HEX format.
    The arabic range in unicode is: 0600�06FF
    But when i convert using Integer.toHexString(), i get hex values which are not in the above range.
    Here goes the code:
    for(int i=0;i<text1.length();i++)
    if((int)text1.charAt(i)<10) {
    hextext+="0"+Integer.toHexString(text1.charAt(i)).toUpperCase();
    else {
    hextext+=Integer.toHexString(text1.charAt(i)).toUpperCase();
    Regards,

    http://forum.java.sun.com/thread.jspa?threadID=682398&messageID=3975945#3975945

  • How to convert a string to hex in TestStand

    Hi everyone, I think this is a fairly easy question to answer but I am newer to TestStand.
    In one step I am pulling in the Serial Number of a Device (which is alpha and numeric characters) and storing it as a String Local called Local.SerialNumberString.  In the following step I need to convert this Local to a Hex value and store it as Locals.SerialNumberHex
    Here is the data representation I need to take place:
    Locals.SerialNumberString = ABC123456
    and would like to know of a function that would convert to the following:
    Locals.SerialNumberHex = 414243313233343536
    How can this be done?
    Thanks so much!

    It looks like what you are asking for is more than just converting to hex, it looks like you want to convert the characters in the string to their ascii value representation and then convert that to hex.
    1) Use a for loop Locals.i = 0; Locals.i < Len(Locals.SerialNumberString); Locals.i++
    2) Inside the loop do: Locals.SerialNumberHex += Str(Asc(Mid(Locals.SerialNumberString, Locals.i, 1)), "%.2x")
    Hope this helps,
    -Doug

  • How can I convert a string of hex values to a hex format string programatically?

    Is there a way to convert a string of the following format:
    1400010107070D0305006A01 ........           ("Normal display" string)
    programatically to:
    1400 0101 0707 0D03 05006A01 ..........      ("Hex display" striing)
    I need to do this in order to calculate a CRC16 value.
    See attached VIs
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    CMM_SN_MULTI.vi ‏50 KB
    CMM_CRC16_Calculator.vi ‏23 KB

    You can iterate over the string and use the String to Hex VI. If you work with two bytes of the string at a time you can get a U8 array of the desired binary values. Then when you are complete you can either work with the byte array of convert it back to a string using Byte Array to String.
    EDIT: GerdW typed faster than I did.
    Message Edited by Mark Yedinak on 03-18-2010 02:55 PM
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Non ASCII String to Hex

    Hi,
    I am writing an algorithm that first encrypts a String, and then converts that String to Hex String. I can successfully parse Hex Strings into Ascii Strings and vice versa, but when I encrypt I cannot do this anymore. Is there a way to convert a non-ascii character to Hexadecimal and vice versa?
    Thanks in advance

    Maybe so....
    The encrypted value when printed does not format on my screen, and appears as boxes and such.
    The values that I am passing in are a very simple encryption....XOR against a key. Here is that algorithm.
    public byte[] encrypt(byte[] value) {
              byte[] encrypted = new byte[value.length];
              byte[] adjustedKey = getKey();
              while (adjustedKey.length < encrypted.length) {
                   String temp = new String(adjustedKey) + new String(key);
                   adjustedKey = temp.getBytes();
              for (int i = 0; i < value.length; i++) {
                   encrypted[i] = (byte)(adjustedKey[i] ^ value);
              return encrypted;          
    Since this is an XOR, I can use the same method to decrypt as well. This is what produces my non-Ascii characters.
    Is there a way for me to get the byte value of a 1 digit hex value then? this may help some.

  • Exception occuring while i'm trying to convert decimal to Hex

    Hello all you genius people, please help me out. I'm using this simple code(given below) to read String from a file then convert it to Hex and write in anoher file. But i'm getting this exception that, after reading few lines it gives such exception:
    java.lang.NumberFormatException: For input string: "2826111134"
    import java.io.*;
    public class DecimalToHexConv {
      String line;
      String hexEsn;
      String temp;
      int esn=0;
      public DecimalToHexConv(){
      try{
        FileWriter fwr = new FileWriter("CTGHLR201005_out.txt");
        BufferedReader bfr = new BufferedReader(new FileReader("testin.txt"));
        while((line=bfr.readLine())!=null){
          line= line.replace('|',';');
          String spl[] = line.split(";");
          esn = Integer.parseInt(spl[2].toString().trim());
          hexEsn = (Integer.toHexString(esn)).toUpperCase();
          temp= spl[0]+"|"+spl[1]+"|"+hexEsn+"\n";
          System.out.print(temp);
          fwr.write(temp);
        fwr.close();
      catch(Exception e){
        System.out.println("Exception: "+e);
      public static void main(String[] args) throws Exception {
        DecimalToHexConv dtc = new DecimalToHexConv();
    }output:
    4702181500|11800467|2FA42C8B
    4702825345|11704172|620A4CFC
    4703200000|11200000|52B53DB9
    4703200001|11200001|52156AC7
    Exception: java.lang.NumberFormatException: For input string: "2826111134"
    testin.txt:
    4702181500|11800467|799288459
    4702825345|11704172|1644842236
    4703200000|11200000|1387609529
    4703200001|11200001|1377135303
    4703200046|11200046|2826111134
    4703200000|11200000|1387609529
    4703200001|11200001|1377135303
    So after converting first 4 lines i got the exception. Please hep me out.. that what is wrong???
    Regards
    Sahrear

    But i'm getting this exception that,
    after reading few lines it gives such exception:
    java.lang.NumberFormatException: For input string:
    "2826111134"It's because the biggest number an int can hold is 2147483647. You can use long insted. It can hold bigger numbers but understand that it has an upper limit too.

  • Converting BLOB to HEX and HEX to BLOB

    Hi!
    I have a table that stores pictures as BLOB. Due to some project rules, I need to be able to convert this image to a CLOB (represented as a HEX String) and, after that, I need to convert this HEX String back to BLOB.
    I already created the function that converts BLOB to HEX. See below:
    CREATE OR REPLACE FUNCTION blob_to_hex (blob_in IN BLOB)
    RETURN CLOB
    AS
        v_clob    CLOB;
        v_varchar VARCHAR2(32767);
        v_start   PLS_INTEGER := 1;
        v_buffer  PLS_INTEGER := 32767;
    BEGIN
        DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
        FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(blob_in) / v_buffer)
        LOOP
           v_varchar := DBMS_LOB.SUBSTR(blob_in, v_buffer, v_start);
           DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
           v_start := v_start + v_buffer;
        END LOOP;
       RETURN v_clob;
    END blob_to_hex;But, I´am having some difficulties to convert the HEX CLOB back to BLOB.
    Does anybody know how could I do this?
    Thanks a lot!!!
    Regis

    try this procedure
    first create directory BLOB_DIR
    CREATE OR REPLACE DIRECTORY
    BLOB_DIR AS 'C:\temp';
    CREATE OR REPLACE PROCEDURE BLOB_LOAD(filename varchar2)
    AS
    lBlob BLOB;
    lFile BFILE := BFILENAME('BLOB_DIR', filename);
    BEGIN
    INSERT INTO O_CONTRACT_IMAGES
    (CONTRACT_NO,CONTRACT_Year,CONTRACT_blob)
    VALUES (1,2, empty_blob())
    RETURNING CONTRACT_blob INTO lBlob;
    DBMS_LOB.OPEN(lFile, DBMS_LOB.LOB_READONLY);
    DBMS_LOB.OPEN(lBlob, DBMS_LOB.LOB_READWRITE);
    DBMS_LOB.LOADFROMFILE(DEST_LOB => lBlob,
    SRC_LOB => lFile,
    AMOUNT => DBMS_LOB.GETLENGTH(lFile));
    DBMS_LOB.CLOSE(lFile);
    DBMS_LOB.CLOSE(lBlob);
    COMMIT;
    END;
    Edited by: Hossam Kasem on 20-Apr-2011 05:56

  • JMS Correlation ID not converting to EBCDIC Hexa

    We are using the PI 7.1 system on a AIX platform.
    We use the JMS adapter to send messages to a MQ Queue manager on a AS400platform.
    WebSphereMQ transport protocol is in JMS adapter.
    We are generating custom dynamic correlation id using a UDF.
    Expectation is to receive the correlation id in Ebcdic format because the
    receiving end is a AS400 system.
    But what I receive there is a Ascii Hexa.
    For a example we are sending the correlation id as 0180000012. (ASCII)
    What MQ receive is 30313830303030303132 (ASCII HEX)
    Where what MQ should receive is F0F1F8F0F0F0F0F0F1F2 (EBCDIC HEX)
    I need help to find out why JMS adapter is converting the correlation id
    in to ASCII HEX without converting to EBCDIC HEX.
    Appreciate a lot if any one can provide some help on this.
    Thanks a lot,
    Tania.

    I am not sure if I have understand the issue correctly.
    Do you create an ASCII string and the ASCII characters are not converted into EBCDIC,
    or do you create a HEX String?
    Or does the JMS adapter converts your ASCII string to Hex?
    I have the impression that the behaviour is a design gap, which nobody has noticed before.
    A work around could be in converting the ASCII to EBCDIC inside the UDF,
    Report this to SAP

  • How to convert signed ascii hex to float value

    Hi,
    I have a requirement to convert IEEE ascii hex to float value.
    Following code is working for +ve float value but it didn't work for -ve.
    public static float hexToFloat(String str){
              float floatVal= 0.0f;
              int decimalValue =Integer.parseInt(str,16);
              floatVal=Float.intBitsToFloat(decimalValue );
              return floatVal;
    for example "BE4CE1E6" should return -0.20 . (i verified in http://babbage.cs.qc.edu/IEEE-754/32bit.html )
    For the above string I am getting number format exception.
    pls help me.

    The problem is the parseInt method. It can only process numbers up to 2147483647 or 7FFFFFFF. Because that method expects a signed number.
    The solution is to use Long.parseLong() instead.
    public static float hexToFloat(String str){
    float floatVal= 0.0f;
    int decimalValue =(int)Long.parseLong(str,16);
    floatVal=Float.intBitsToFloat(decimalValue );
    return floatVal;
    }

  • Bit-String to Hex

    Hello
    I've got following question: I have a STRING of bits e.g. "01001010". Is there any function to convert it to Hex - code?

    See the attached code. I wasn't sure by what you meant by a "STRING of bits" so it shows two different things.
    Remember also that the distinctions between binary, decimal and hex are only significant to human beings reading the numbers--computers don't really care. An unsigned 8-bit value is an unsigned 8-bit value, regardless of how it's represented for human consumption.
    Note that in a array the LSB is the first element. In a string, the LSB is the far right-hand digit.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
    Attachments:
    formatting.vi ‏18 KB

  • Lost Digits of big Number - convert Double into Hex

    My Number is 24563383270390080
    if i debug the Variable it has got a value of 2.45633832703901e+016, so i lost a little bit of the value.
    if i bring ist into a sting, i can see the complete value "24563383270390080"
    i have to convert the number in to a Hex-Value, the Reuslt should be "$57444456503941" an can be written into a string.
    my problem is to bring the original value into a string of hex, because diadem round the last digits of my number
    i tryed several convertions, but the the probmel of lost digits is still there....
    maybe you´ve got an idea
    dim Number, NumberString, HexTest1, HexTest2, HexTarget
    Number = 24563383270390080  '17 Digits
    HexTarget = "$57444456503941"
    NumberString = Str(Number, "d")
    HexTest1  = Str((Data.Root.ChannelGroups("Neu").Channels("Vin_Data").Values(1)), "$")
    HexTest2  = Str(Val(Number), "$")
    '---> Result
    ''--> Number       = 2.45633832703901e+016
    '--> NumberString = "24563383270390080"
    '--> HexTarget  = "$57444456503941"  
    '--> HextTest1  =  $57444456503940  !!!!! Last Postion !!!!
    '--> HextTest2  =  $57444456503940

    You are a little bit out of luck with your example because
    dim number : Number = 24563383270390080 '17 Digits
    dim txt
    txt = txt & Str(Number, "d") & " ref: 24563383270390080" & VBCRLF
    txt = txt & Str(Number, "$") & " ref: $57444456503940" & VBCRLF
    MsgBox txt
     0 at the end is correct. (At least the MS calculator says so.) But this is by incident because of the number you picked.
    VBS only supports 64 bit double values. 64 bit doubles have a mantissa of 52 bits.
    24563383270390080
    becomes
    1010111010001000100010001010110010100000011100101000000
    which has 55 bit in use. Because your last bits aren't in use the number you picked can be represented by a double without loosing precission.
    24563383270390081
    would show the behavior you described because it is using 55bit range. The 1 is just cut when converted to double.
    But I have no solution for this because it will not work with VBS.

  • BIG ASCII string to HEX string

    Hello guys,
    I know that is already a lot of posts regarding this issue, but I couldn't find exactly what I need and also couldn't manage to solve it myself...
    I need to convert a string with ASCII characters to a string containing HEX representation of these characters.
    What I did was: 
    Apparently it works very well, but only for a limited numbers of characters, defined by data representation of the 0 constant (U64). It allows me to convert only 8 ASCII characters, as you can see on the image below:
    So, it converted from 0 to 7, but not the remaining characters (8 and 9).
    Any ideas??
    Thanks in advance!
     

    What is the data type of the constant wired into the typecast.  My guess is it is a U64.  So it will only typecast the first 8 bytes of your string to a number, then you are doing hex on those 8 numbers.
    Use the function String to Byte Array.  Or you could also typecast where an array of U8 integers is wired into the typecast function.

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

Maybe you are looking for

  • PayloadSwapBean: Sender mail adapter

    Does any codeing is required after adding payloadswapbean in the adpater module in sender mail adpter ?

  • How do I email a scanned document for pixma pringting soloutions

    I just got set up and scanned a document using my canon mg3520 all in one printer to my ipad air and I want to email it but can't figure out how to

  • Subscript out of range

    hi thisis the script i am using to allocate gross invoice percentage for month and total them to show in another row *SELECT (%ENTITY%, "[ID]", "ENTITY", "[ID]='%ENTITY_SET%'") *XDIM_MEMBERSET CATEGORY=ACT *XDIM_MEMBERSET RPTCURRENCY1=LC *XDIM_MEMBER

  • Online Bill Pay

    I cannot access the bill pay feature online, to either view or pay my bill.  After my last account review and affiliated changes, I lost the autopay feature which I had been using.  Now when I go online, I sign in and it directs me to another site fo

  • Missing volume sliders

    so i was working on a song, and when I opened the file up (a new one), the individual volume sliders for each track are not there anymore. to adjust the volume for anything I am forced to open the automation line. has anyone ever had this problem bef