Convert hexadecimal output to decimal (number)

I am reading hexadecimal format from the output of the VISA read block and I want to convert it to the decimal preferably exponential format.
Example of what I read is 76 00 02 (in dec: 7.600 E+2).
I know there is "type cast" block that converts nicelly but I am not sure what to specify for a type input.
Can you show me how to apply this type cast block for in my VI so that it converts hex string (76 00 02) into exponential string/number (7.600 E+2)?
I attached my VI so it is more clear.
Thanks everybody,
Pedja
Attachments:
MultiGauge.vi ‏64 KB

Coop wrote:
> I am reading hexadecimal format from the output of the VISA read block
> and I want to convert it to the decimal preferably exponential format.
> Example of what I read is 76 00 02 (in dec: 7.600 E+2).
> I know there is "type cast" block that converts nicelly but I am not
> sure what to specify for a type input.
> Can you show me how to apply this type cast block for in my VI so that
> it converts hex string (76 00 02) into exponential string/number
> (7.600 E+2)?
Looking at your code I see that you have not a hexadecimal string coming
back but instead a binary string. The fact that you display the string
as hexadecimal in the string indicator is just showing you the ASCII
codes of the string characters as hexadecimal numbers.
The funct
ion From Hexadecimal String expects a clear text string with
hexadecimal characters but that is something entirely different from a
binary string you choose to display as hexadecimal numbers.
An example: the binary string 7600 02 you receive from the device is in
fact the character 'v', a null character and a 02 character (or in ASCII
terms a start of text character).
So assuming your example is right (which I have to admit seems very
strange and therefore suspicious to me) you would have to do something
more like included example. But as I said I have little understanding
why the hexadecimal interpretation of the binary values should
correspond to the decimal value you want to have!
Also as you can see there is not really clear where the 00 character
belongs to. The two methods where it is either part of the multiplier or
the exponent both produce the same result for this particular example.
Which one is right if any, should be tested.
Rolf Kalbermatter
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions
Attachments:
Binary_(Hex)_to_Decimal_Numeric.vi ‏51 KB

Similar Messages

  • Output decimal number through GPIB or VISA

    I was wondering if it is possible to output a decimal number, as in not a string, through the GPIB or VISA commands. I am trying to communicate with a machine that I think wants to get a number, and can't understand what I am sending when it is in a string format.
    thanks

    It is possible to transmit such a number over GPIB. I would double check the instrument manual for what it requires. I'm going to assume that you are using a long to represent a floating pont number. Here is some example code for how you would pass this number to the GPIB ibwrt() function.
    int ud = ibdev(board,PAD,SAD,timeout,eot,eos);
    long myNumber = 4.2;
    ibwrt(ud, &myNumber, sizeof(long));
    Essentially, the driver will break down the 32-bit number into 4 8-bit chunks.
    Craig A.
    National Instruments Engineer

  • How could I choose some bytes from HEX string and then convert it to a decimal value?

    Hi I am working with an OMRON E5EN temperature controller using VISA serial to get data, I send the Read from Variable Area command and get this string  in hexa 0230 3130 3030 3030 3130 3130 3030 3030 3030 3030 3041 3203 71 or .01000001010000000000A2.q in ASCII this string means:
    02 STX
    3031 3030 Node and subadress
    3030 End Code Normal Completion
    3031 3031 Command Read from Variable Area
    3030 3030 respt code Normal completion
    3030 3030 3030 4132 Hexadecimal A2 = 162  (this is the temperature data that I want to show in decimal)
    03 ETX
    71 Block Check Character
    I want to choose the eight bytes for the temperature data and convert it to a decimal number. I have seen the examples to convert a Hexa string to decimal but I do not know how to choose the specifics bytes that I need.
    I have look for a driver but i didn´t find any. I am a beginner so please include especific topics for me to study in your answer.
    Thanks
    Carlos Fuentes Silva Queretaro Mexico 

    If the response always has the temperature starting with byte 15 and is always 8 bytes in length, you can use the String Subset function to get those bytes out of the string.  Then use Hex String to Number to convert to a decimal number.
    Well someone already beat me to the solution:
    Message Edited by tbob on 01-04-2008 04:42 PM
    - tbob
    Inventor of the WORM Global
    Attachments:
    HexStr2Decimal.png ‏7 KB

  • How to convert fractional decimal number to hex number?

    Hi,
    Can any one help me to convert the fractional decimal number to its equivalent hex number and vice versa ?
    if u have any code please share.
    thanks
    neethu

    neethukk wrote:
    Can any one help me to convert the fractional decimal number to its equivalent hex number and vice versa ?
    if u have any code please share.
    This question is not clear at all.
    "Fractional decimal" is not a data type, but a way of formatting in readable form using numeric characters and a decimal separator.
    Same to "hex number", but only for integers.
    What do you mean by "convert"? Do you want to keep the value the same or retain the bit pattern of the numeric data type?
    Hexadecimal is for integers. Are you talking about fixed point?
    We clearly need significantly more information. What are the input and output data types? What are you actually trying to do?
    Do you have an example input and corresponding output?
    LabVIEW Champion . Do more with less code and in less time .

  • How to convert data read in byte to decimal number?

    The following are a source code to read from a serial port, but i can't convert the data that i read to decimal number and write it on a text file.....can anyone kindly show me how to solve it? thanks
    import javax.comm.*;
    import java.io.*;
    import java.util.*;
    public class Read implements Runnable, SerialPortEventListener {
         // Attributes for Serial Communication
         static Enumeration portList;
         static CommPortIdentifier portId;
         SerialPort serialPort;
         static OutputStream outputStream;
         InputStream inputStream;
         Thread readThread;
         public static void main(String s[])
         portList=CommPortIdentifier.getPortIdentifiers();
         while(portList.hasMoreElements())
              portId=(CommPortIdentifier)portList.nextElement();
              if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL)
                   if(portId.getName().equals("COM1"))
                        System.out.println( portId.getName());
                        Read ss=new Read();
              }     // end of while
    }          // end of main
    public Read()     {
    try{
              serialPort=(SerialPort)portId.open("Read", 2000);
    catch(PortInUseException e)     {}
         try{
              inputStream=serialPort.getInputStream();
              System.out.println(inputStream);
    catch(IOException e)     {}
         try{
              serialPort.addEventListener(this);
    catch(Exception e)     {}
              serialPort.notifyOnDataAvailable(true);
         try{
              serialPort.setSerialPortParams(9600,
              SerialPort.DATABITS_8,
              SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
              }catch(UnsupportedCommOperationException e)     {}
              readThread=new Thread(this);
              readThread.start();
         }//end of constructor
         public void run()
              try     {
                   Thread.sleep(200);
              }catch(InterruptedException e)     {}
         public void serialEvent(SerialPortEvent event)
              switch(event.getEventType())
                   case SerialPortEvent.BI:
                   case SerialPortEvent.OE:
                   case SerialPortEvent.FE:
                   case SerialPortEvent.PE:
                   case SerialPortEvent.CD:
                   case SerialPortEvent.CTS:
                   case SerialPortEvent.DSR:
                   case SerialPortEvent.RI:
                   case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                   break;
                   case SerialPortEvent.DATA_AVAILABLE:
                   byte[]readBuffer=new byte[8];
                   try{
                        while(inputStream.available()>0)
                             int numBytes=inputStream.read(readBuffer);
                             //System.out.println("hello");
                        System.out.print(new String(readBuffer));
                        }catch(IOException e)     {}
                   break;
                   }     // end of switch
                   try     {
                        inputStream.close();
                        }catch(Exception e5)     {}
         }          // end of serialEvent

    Is it a float or a double?
    For a float, the decimal should be 4 bytes (small numbers like 1.1 start with the byte 0x40). Convert these 4 bytes to an int, using byte-shifting would probably be easiest.
    int value = ((b3 << 24) + (b2 << 16) + (b1 << 8) + b0);//b# are bytesNow to convert it to a float, use
    Float.intBitsToFloat(value);Now if you want double percision, You will have 8 bytes instead of 4, and need to be converted to a long instead of an int through byte-shifting. Then use Double.longBitsToDouble(long bits) to get the double

  • Program to convert binary to decimal number?

    I only know how to do a program that converts only 4 numbers, but it to convert any amount of digits the number enters, I think you need to use a loop or something, but I'm not sure how. Could someone please help me? This is my code so far:
    import javax.swing.JOptionPane;
    public class bintodec {
         public static void main (String[] args) {
              String input;
              int number,digit1,digit2,digit3,digit4,result;
              input = JOptionPane.showInputDialog ("Enter a binary number.");
              number = Integer.parseInt(input);
              digit1 = ((number % 10000) - (number % 10000 % 1000)) / 1000;
              digit2 = ((number % 1000) - (number % 1000 % 100)) / 100;
              digit3 = ((number % 100) - (number % 100 % 10)) / 10;
              digit4 = (number % 10);
              result = (digit1 * 8) + (digit2 * 4) + (digit3 * 2) + (digit4 * 1);
              System.out.println ( "Binary number: " + input + "\nConverted Decimal Number: " + result);
              System.exit( 0 );
         } // main
    } // bintodecany help is super-appreciated.

    I am not sure if this will help you. Check it out, run it and let me know if it helped.
    import java.util.*;
       public class BitwiseTest1 {
           public static void main(String[] args){
            System.out.println("Enter a integer number:");
            Scanner keyboard = new Scanner(System.in);
            int n1 = keyboard.nextInt();
            System.out.println( "n1 as binary " +
                   Integer.toBinaryString( n1 ));
            System.out.println( "NOT n1 =     " +
                   Integer.toBinaryString( ~n1 ));
            System.out.println("Enter another integer number:");
            int n2 = keyboard.nextInt();
            System.out.println( "n2 as binary " +
                   Integer.toBinaryString( n2 ));
             System.out.println( "NOT n2 =     " +
                   Integer.toBinaryString( ~n2 ));
    }

  • Is there any function module to convert hexadecimal format to normal decima

    Hi,
    is there any function module to convert hexadecimal format to normal decimals.
    Regards,
    Nandha.

    HI Naddy,
    simply do this..
    parameters  : num1(5) type x.
    data : dec type i.
    dec = num1.
    write : dec.
    remember to pad the input with zeros
    regards
    satesh

  • Regarding Converting the Decimal number into rounded value...

    Hi,
       i have a decimal number as "   58240990.00 " , i wanted this to rounded value .
      for example I am expecting to see 58241 for the above number.
      shell we can do in any way.. if so please let me knw fast.. it is urgent..
      thanks in advance.
    thanks,
    Suresh..

    Dear Suresh,
    Go through the following code chunk:
    DATA : p TYPE p DECIMALS 2 VALUE '2.49'.
    DATA i TYPE i.
    i = CEIL( p ).
    WRITE : i.
    Regards,
    Abir
    Don't forget to award Points *

  • Convert a String to Decimal Format in European format

    Hi Experts,
    I am having a string as a context type for a input field, where the user can enter the Price, I need to convert the same into European format "###.###,00", I am using this below code to convert the string to decimal format
    User will enter the input as 10 as it needs to be converted into 10,00. Also, 1000 which has to be converted as 1.000,00
    String Str1 = wdContext.currentvn_temptable.getVa_TempUnitPrice();
    Locale mylocale  = Locale.GERMAN;
    String pattern="###.###,00";                    
    NumberFormat nf = NumberFormat.getNumberInstance(mylocale);
    DecimalFormat df = (DecimalFormat)nf;
    df.applyPattern(pattern);
    String output = df.format(Str1);
    wdComponentAPI.getMessageManager().reportSuccess("Unit Price" + " " + pattern + " " + output);
    When I execute the above code, i am getting an error called "Malformed Pattern ###.###,00"
    Please let me know, how to convert a String to Quantity in European format
    Thanks & Regards,
    Palani

    Hello!
    Try to change your pattern to this one 
    Locale mylocale  = Locale.GERMAN;
    String pattern = "#,#00.00";                    
    NumberFormat nf = NumberFormat.getNumberInstance(mylocale);
    DecimalFormat df = (DecimalFormat)nf;
    df.applyPattern(pattern);
    String output = df.format(1111111.222);
    Pattern has an influence on number of digits between separators, but you have to use ',' for grouping and '.' for decimal. Character values for separators correspond to your Locale object.
    Thanks, Mikhail

  • Conversion of hexadecimal file to decimal file in labview

    hi all,
    I took a measurement from an anemometer by its original program. I attached the file below. I want to convert this file to the decimal file. I all know is the data in file are in hexadecimal and 16-byte. How can I convert this file to decimal one? I prepared something as I saw in this forum but it gives me just one number. I attached the vi below too.
    Egemen
    Attachments:
    Z-D6_Z-D0_ST0_RE_7958.zip ‏1 KB
    hex to decimal.vi ‏8 KB

    GerdW wrote:
    Hi newbie,
    it doesn't make sense to convert the filename to some other datatypes. You have to load the datafile first!
    @Bijay: as the file is no spreadsheetfile it doesn't make sense to load it using ReadFromSpreadsheetFile!
    You may try this:
    The file seems to contain SGL values so I typecasted them. If that's not the case you use the U8 array to do your own computations...
    Edit:
    Using ReadBinaryfile is somewhat easier...
    "the data in file are in hexadecimal and 16-byte."
    The file isn't in hexadecimal, it's just binary. And what do you mean by "16-byte"???
    I tried your suggestion and find something what I really do not know what they are. I attached the results print screen. I will try the second solution.
    Egemen
    Attachments:
    results.PNG ‏98 KB

  • Convert IPv6 address to decimal

    How do we convert an IPv6 address to its decimal equivalent using java?
    I could find different tools on Internet but not the java code for the same.
    Any help would be much appreciated.
    Thanks.

    Hello EJP
    Please visit the following URL:
    https://www.ultratools.com/tools/decimalCalcResult?ipAddress=805b%3A2d9d%3Adc28%3A0000%3A0000%3Afc57%3Ad4c8%3A1fff
    This converts the IPv6 address (which is in hexadecimal format) to a decimal number.
    I need to implement this functionality. I could not find any method in java.net.Inet6Address class for this.
    To convert an IPv4 address which is in String format to its decimal equivalent, we can use following method:
    <code>
    long stringToLong(String ipAddress) {
              String[] octets = ipAddress.split("\\.");
              long intValue = 0;
              long currentOctet;
              for (int i = 0; i < octets.length; i++) {
                   currentOctet = new Integer(octets[(octets.length-1)-i]).intValue();
                   intValue = (currentOctet << i*8) | intValue;
              return intValue;
    </code>
    Edited by: 803674 on May 26, 2011 12:22 AM

  • Converting hexadecimal XML data to a string

    Hello!
    Until now I generated XML data with the FM 'SDIXML_DOM_TO_XML'.
    After that I did a loop over the xml_as_table in which I was casting each line of that table to a string.
    ASSIGN <line> TO <line_c> CASTING.
    After the inftroduction of unicode in our system I get a error:
    In the current program an error occured when setting the field symbol <LINE_C> with ASSIGN or ASSIGNING (maybe in combination with the CASTING addition).
    When converting the base entry of the field symbol <LINE_C> (number in base table: 32776), it was found that the target type requests a memory alignment of 2
    What does it mean? Does somebody have a solution.
    I need this function for sending this XML data as string over a simple old CPIC connection.
    Best regards
    Martin

    Hello Martin
    Perhaps my sample report ZUS_SDN_XML_XSTRING_TO_STRING provides a solution for your problem.
    *& Report  ZUS_SDN_XML_XSTRING_TO_STRING
    *& Thread: Converting hexadecimal XML data to a string
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1029652"></a>
    REPORT  zus_sdn_xml_xstring_to_string.
    *-- data
    *-- read the XML document from the frontend machine
    TYPES: BEGIN OF xml_line,
            data(256) TYPE x,
          END OF xml_line.
    DATA: xml_table TYPE TABLE OF xml_line.
    DATA: go_xml_doc       TYPE REF TO cl_xml_document,
          gd_xml_string    TYPE string,
          gd_rc            TYPE i.
    PARAMETERS:
      p_file  TYPE localfile  DEFAULT 'C:payload_idoc.xml'.
    START-OF-SELECTION.
      CREATE OBJECT go_xml_doc.
      " Load XML file from PC and get XML itab
      CALL METHOD go_xml_doc->import_from_file
        EXPORTING
          filename = p_file
        RECEIVING
          retcode  = gd_rc.
      CALL METHOD go_xml_doc->get_as_table
        IMPORTING
          table   = xml_table
    *      size    =
    *      retcode =
    " NOTE: simulate creation of XML itab
      go_xml_doc->display( ).
      create object go_xml_doc.
      CALL METHOD go_xml_doc->parse_table
        EXPORTING
          table   = xml_table
    *      size    = 0
        receiving
          retcode = gd_rc.
      CALL METHOD go_xml_doc->render_2_string
    *    EXPORTING
    *      pretty_print = 'X'
        IMPORTING
          retcode      = gd_rc
          stream       = gd_xml_string
    *      size         =
      write: / gd_xml_string.
    END-OF-SELECTION.
    Regards
      Uwe

  • Comma or point in decimal number

    Hi,
    I wonder how to handle decimal number input from jsp page with comma or point. Is there a way to take care of this automatic so a comma get parsed to a point or vice versa.
    Thanks in advance.

    I don't know if it will be a comma or a dot that is inputed. My keyboard uses a comma on the numeric pad but if i change it to a US keyboard it will use dot instead so I can't tell what a user will input. And if I understand everything when java calculates a double it has to be with a dot, or am I completly wrong.
    So with this in mind i decided to replace all dots with a comma and then parse it to a double with NumberFormat and do my calculation and then format it with NumberFormat again. This works fine and gives me a nice output if no one tries to input more than one point or comma.
    I can't think of another way to do it so if this is completly wrong so please point me in the right direction.

  • Prefix zero to a decimal number

    Hi All,
    I need to send a value to third party system. The value is a decimal number but before sending it i need to prefix zero.
    Eg: 1.25---> 00000000001.25
    The Functiom module CONVERSION_EXIT_ALPHA_INPUT works only for integers.
    Can you please suggest a function module which wil satisfy my requirement.
    Thanks
    Rohit

    Use a For loop to index into the array, then use the Not Equal To Zero comparison to convert it to true/false. Then Index out of the For and use the Bool Array to Int from the boolean pallete.
    Here is an example in 8.2
    Use the rating system, otherwise its useless; and please don't forget to tip your waiters!
    using LV 2010 SP 1, Windows 7
    Attachments:
    Convert Bit Array to Int.vi ‏8 KB

  • My graphical display of converted hexadecimal numbers changes with every run!

    Dear all,
    I've created a Vi that can select and convert hexadecimal numbers from a string array. These hexadecimal numbers contain acceleration data (units g).
    My string array (from line 68+) places every 10 rows a 1 line of hexadecimal number with a length of 300. I've managed to convert this into 1D array DBL.
    My current problem is, when I run my for loop my graphical representation of the acceleration data changes overtime!
    Can anybody help me solve this problem?
    Thanks in advance
    Attachments:
    Hexidecimal Numbers - BIN File GENEA 22-08-12.vi ‏46 KB
    T01Waist_right thigh_011628_2012-02-08 11-15-35.zip ‏750 KB

    I found a little dead time and decided to have a little fun cleaning up.  Notice that I removed the FOR loops on the left side.  The biggest thing was that I used the Read Text File configured to read lines (it gives me an array of the lines in the file), got rid of the first 68 lines, and then passed that array into the FOR loop.  Your code there was next to impossible to figure out, even with the comment.  I have no clue where you came up with trying to update every 25ms.  It shouldn't take your processing that long.  Instead, just index out the lines inside of the loop.
    There's still a bunch of cleaning up to do, but it's quitting time for me.  I'll try to get on sometime this weekend of you have more questions.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Hexidecimal Numbers - BIN File GENEA.vi ‏23 KB

Maybe you are looking for

  • I can't open PDF files with adobe flash player

    I have installed it and whenever I try to open pdf files it says I need to agree with your liscens and you do that automatically when you download it. I have followed all your instructions on your website and uninstalled it and installed again, but I

  • NOT SHOWING UPOI

    hp   Windows XP   ok i bought a tv show from itunes and its not showing up on my ipod nano..can you even watch tv show/movies on ipod nanos?

  • Where can I find Pedobear pics that I can download directly to my iPhone4!

    There Is this app on the AppStore called "funny pics" and every now and then I find a Pedobear pic I am able to download the pic from within the app and upload them to facebook. I personally post a funny pic per day and would LOVE to get more Pedobea

  • Help! why can't i sync my entire photo album onto my phone?

    I used to sync my entire photos in iphoto onto my iphone 3. Now that i have changed to iphone 4, it can only sync some of my photos. IT says, ' It says: "Some of your photos, including the photo "DSC04441.JPG", were not copied to the iPhone "adelehen

  • Nested aggregation and additional sql in query

    Hi experts, I need to create a measure in the rpd that will look like: measure 1 = SUM(count distinct (ID)) over(order by T11687.MON_CODE asc rows unbounded preceding) Is it possible to have a nested aggregation and the over (...) in the query that w