Conversion of binary to number

Hello,
I have a signal conditioner controlled through serial communication with ASCII commands. Once the start command is received, there is a continuous stream of offset binary data sent and read through the serial Read Indicator. The manual informs me that I must first condition the offset binary values by subtracting 2048 from the raw values to produce a 2's complement value,  it also mentions that the data is encoded in 12 bits so negative numbers must be properly sign extended to move the data into 16 bit words used by the PC. I am not familiar with binary numbers and am unsure on where to start. If someone could provide some insight and suggestions on what my first step would be to converting the binary values into number format, that would be greatly appreciated.
Thank you in advance,
Jena

That won't work because he's not receiving the string the way you think it is. The hex display is an interpretation of the underlying byte values. It is not the same as number written out in hex as a string. Your conversion assumes he's getting the character 1, followed by the character 8, followed by the character 0, followed by the character 0, followed by a space character.
The simplest way is to use the Type Cast function, 'cause that's what it's there for. Wire in an array of the datatype you want. The thing to keep in mind is that even though the data may be fundamentally 12 bits you need to deal with multiples of 8 because a serial read will read bytes, not bits. Thus, you can convert your string to an array of I16 numbers like this:
Message Edited by smercurio_fc on 04-08-2008 01:07 PM
Attachments:
Example_VI_BD2.png ‏2 KB

Similar Messages

  • Number to a binary base number

    How can I convert a numeric data to a binary base number?
    Ex.: A into 0001010
    Thank you in advance

    OK, only conversion to a string is needed to solve the problem. (Everything else is just a cosmetic feature of the indicator where you set the formatting. This does not change the underlying data.)
    Just use "format into string" with a format code of "%07b" (=show seven binary digits and pad with zeroes to the left).
    LabVIEW Champion . Do more with less code and in less time .

  • Binary or number string

    Hi...
    How can I know if a string is a binary or number?
    thank you.

    You can only test for a String not containing a binary number like this..
    boolean isNotBinary = ( someString.indexOf( "0" ) == -1 && someString.indexOf( "1 ) == -1 );As a number can be anything with "-012345678eE." and has to adhere to a specific format to qualify as a number AND the fact that the radix makes everything ambiguous determining if a String contains a number and is binary becomes horribly complicated.
    Your definition of number needs to be more tightly defined, integer/long, float/double, fixed decimal and integer/long numbers with different radix need to be considered before you can test for numberness.

  • Number conversion to binary

    Hello,
    Oracle Info:
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE 9.2.0.1.0 Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 – Production
    OS Info:
    Microsoft Windows XP Professional Version 2002
    Service Pack 1
    Is there any PL/SQL code, by which we can convert numbers to its binary representation? Numbers can be something like these:
    25,2008,-25,-2008,25.23,-25.23,2008.0701,-1715.1253 etc. (any number value)
    Thanks & Regards
    Girish

    Sir, thanks for your compliments.
    There is no limit for bit selection. If the number
    fits in 8 bit then result should be in 8 bit
    representation otherwise more required bits would be
    there.Ok, consider I show you two binary numbers...
    11001101
    and
    1001010010
    Which one is positive and which one is negative?
    Without stipulating the number of bits you are working with nobody can tell. This is a key requirement of working with postitive and negative integers.
    As an example bring up Micro$ofts calculator in windows and ensure you have it set to scientific mode. Enter a simple negative number in decimal e.g. -5 and then click on the Bin radio button and look at the result...
    1111111111111111111111111111111111111111111111111111111111111011
    This is because Microsoft have stipulated that they are using 64 bit numbers, they don't just put 1011 or 11011 or 111011; all of which could be -5 but you can't be sure.
    Suppose, I have created a table having 2
    columns; first column will carry number value and
    another column will carry binary representation
    varchar2(4000) length. I am trying for this just for
    increase PL/SQL programming skills and computer
    fundamentals as well.Well as you know the 2's complement of negative numbers you should easily be able to write some SQL and/or PL/SQL that can give a string representation of the binary +ve and -ve number.
    You're decimal numbers will be more difficult to represent as you need to determine if you are just going to use a binary representation of the number to the left and right of the decimal point and show that as binary with a decimal point in the equivalent place or whether you are going to reserve the lower X number of bits for the number to the right of the decimal point, or are you going to represent the whole number as a binary integer and store additional information giving the position of the decimal point (i.e. how much to divide by 10 is required)
    Your choice.

  • Conversion of binary string into headecimal

    Ho will i convert binary string into hexadecimal fromat

    HI,
    Thanks but the above module is not present my system.
    I have number which needs to be converted into binary first and then into Hex.
    I have written it code for conversion of decimal number into Binary.But i am not able to convert it into Hex.
    My rough code is ....
    types : begin of t_temp,
            r1 type i,
            end of t_temp.
    data : ty_temp type standard table of t_temp ,
           wa_temp type t_temp.
    DATA : num TYPE i,
           temp1 TYPE string,
           temp2 TYPE string,
           temp3 TYPE string,
           temp4 TYPE x.
    temp1 = 0.
    temp2 = ''.
    num = 64.
    while num ne 1.
      temp1 = num MOD 2.
      num = num / 2.
      If temp1 = 1.
        num = num - 1.
      endif.
      concatenate temp1 temp2 into temp2 .
    endwhile.
      temp1 = 1.
      concatenate temp1 temp2 into temp2 .
      condense temp2 no-gaps .
      WRITE : temp2 .

  • I got a new phone and phone number two weeks ago, I like to iMessage on my macbook pro but none of my new conversations show up, I went into the preferences to change the settings so only conversations from my new number show up, but there is no change.

    If anyone can please help me, I would like to continue using iMessage on my laptop, but none of my new conversations exist only the older ones. I went into the iMessage preferences to delete my old number off the iMessage account and added my new number and email but I still don't get any new messages. Can somebody please tell me what I am doing wrong or how to change it further?
    Please and thanks.

    If the modem is also a router, either use the modem in bridge and run pppoe client on the TC.. that is assuming ADSL or similar eg vdsl. If it is cable service.. and the modem is a router, then bridge the TC.. go to internet page and select connect by ethernet and below that set connection sharing to bridge.
    Please tell us more about the modem if the above gives you issues.

  • Calling a procedure from java, conversion from bigdecimal to number(13,3)

    Hello
    i have a procedure that i call from a java api
    among the parameter that i give to the procedure there is a bigdecimal parameter
    then i have to insert this value in a table
    the colum concerned has number(13.3) as a type
    here is the java call :
    ps.setBigDecimal(5,value );
    so what type should i declare for the procedure parameter for the bigdecimal parameter
    and is there a conversion to do
    Regards
    Sallemel

    Data types are defined by the data not a column definition. What are the range of values possible in the data that must be manipulated. Give examples.

  • Conversion from date to number & display a date in a textfield

    I Have 2 issues
    The first one:
    I need to extract the hour from a date variable.
    This is the code I already have:
    NUM_TOT := NUM_TEL + to_number('PROGRAMMINGS1.PRG_START','hh24');
    NUM_TOT & NUM_TEL are number variables,
    PROGRAMMINGS1.PRG_START is a Textfiel with a dateformat. There can only be an houre like 24:59:00 entered.
    So in this example I just want the houre and convert it to a number.
    The second:
    I want to make a date from a few numbers & then display it in a texfield.
    This is the code I already have:
    VAR_DATE := NUM_TEL || ':' || NUM_LENGTH || ':00';
    :PROGRAMMINGS.PRG_END := to_date(VAR_DATE,'hh24:mi:ss');
    Between the 2 lines of code i places a message(VAR_DATE) for testing.
    When the program display VAR_DATE then i can see the good date at the bottom of the screen.
    But when I place my variable in the textfield it looks like: 00:00:00. What am I doing wrong?
    Who can help me.
    With regards
    Stefanie

    Verdi wrote:
    Problem: During the conversion (both implicit and explicit conversion with a format mask) I lose the "00" hours and "00" minutes and receive something like this: "10-JAN-13 *12*.00.00.000000000 AM".I don't think you are necessarily losing any information whatsoever. It's probably more of a function of your NLS_TIMESTAMP_FORMAT and NLS_DATE_FORMAT. For example your NLS_DATE_FORMAT could be setup by default for a HH24 (24 hour time) which would report midnight as "00" hours. However, it looks like your NLS_TIMESTAMP_FORMAT is setup with a "HH" format with a meridian indicator which means 12 hours time.
    Your comparisons should be using date/timestamp data types anyways so as long as the input value is converted properly into a date type this shouldn't matter anyways.
    You can see what is actually stored by using the DUMP function:
    SQL> SELECT  DUMP(TO_TIMESTAMP(TO_CHAR(TRUNC(SYSDATE,'DD'),'MM/DD/YYYY HH:MI:SS AM'))) AS TSTAMP
      2  ,       DUMP(TRUNC(SYSDATE,'DD')) AS DT
      3  FROM DUAL
      4  /
    TSTAMP                                                                      DT
    Typ=187 Len=20: 218,7,1,13,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0                  Typ=13 Len=8: 218,7,1,13,0,0,0,0As you can see the TSTAMP and DT store nearly the same values (218,7,1,13), but the TSTAMP has more precision because of fractional seconds.
    HTH!
    Edited by: Centinul on Jan 13, 2010 7:23 AM

  • Conversion from Binary to decimal - Need help

    Hi guys,
    I am new here and learnt some very basic Java before. I have a program that is in C++(to convert a binary number to decimal) that I found in the internet that interest me a lot. I am thinking whether this can be re-write in Java. I have tried to searh for solution but to no avail. I am wondering whether you guys can suggest a solution to this. Below are the source code in C++ :
    #include <iostream.h>
    #include <stdlib.h>
    int main()
    // part 1 : declaration
    int Bin, Dec, TempBin;
    int div;
    char valid, again;
    do {
    // part 2 : Repeat asking the value of the binary number
    Bin = TempBin = 0;
    do {
    cout << "Please input a binary number (1 to 10 bits) : ";
    cin >> Bin;
    TempBin = Bin;
    do {
    if ((TempBin % 10)==0 || (TempBin % 10)==1) // Note (1)
    valid='Y';
    else {
    cout << "Invalid pattern! use 0's and 1's only\n\n";
    valid='N';
    break;
    TempBin = (TempBin/10);
    } while (TempBin>0);
    } while (valid=='N');
    // part 3 : Convertion
    div = 1;
    Dec = 0;
    TempBin = Bin;
    do {
    Dec += (TempBin % 10)*div; // Note (2)
    div *= 2;
    TempBin = (TempBin/10);
    } while (TempBin>0);
    cout << "\nThe binary pattern " << Bin << " is equal to "
    << Dec << " in decimal pattern.\n" << endl;
    // part 4 : try another number ?
    cout << "\aTry another number (Y/N) : ";
    cin >> again;
    cout << "\n";
    } while (again=='Y' || again=='y');
    cout << "\n" << endl;
    system("PAUSE");
    return 0;
    Appreciate your help. Thank you.
    CK

    So for Java, in your example, it takes a Java
    String like "1001" and converts it to an int whose
    value is one thousand and one. Can suggest a code for
    this that takes user input str and convert to bin int.
    I read books and noticed they are various ways to do
    that. I am quite confused actually. It is like there
    is no fix way to do that, unlike C++ which is more
    easier to understand(in my opinion). Probably, because
    I knew C better than Java.
    The 'standard' way to take a String and convert it to an int...
    int TempBin=Integer.parseInt(your_string);
    You seem to be saying that you do not want to use the standard method, so you should not complain that there is no standard method. Here's some code that re-uses most of your modulo 10.
    import java.io.*;
    public class Test {
         public static void main(String []args) throws IOException {
              BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
              String result=null;
              while(true) {
                   String input=bf.readLine().trim();
                   try {
                        long v=Long.parseLong(input);
                        result=toBin(v);
                        System.out.println(result);
                   } catch(NumberFormatException e) {
                             System.out.println("Only enter 1 or 0, nothing else!");
                   System.out.println();
           public static String toBin(long btemp) {
              long temp=btemp;
              do {
                   if ((temp % 10)!=0 && (temp % 10)!=1) {
                        System.out.println("Invalid pattern! use 0's and 1's only\n\n");
                        return null;
                   temp = (temp/10);
              } while (temp>0);
              // part 3 : Convertion
              int div = 1;
              int Dec = 0;
              long TempBin = btemp;
              do {
                   Dec += (TempBin % 10)*div; // Note (2)
                   div *= 2;
                   TempBin = (TempBin/10);
              } while (TempBin>0);
              return ""+Dec;

  • Binary Tree: Number of Nodes at a Particular Level

    Hi, I'm trying to teach myself about binary tree but am having trouble writing an algorithm. The algorithm that I'm trying to write is one that will take a binary tree and output the number of nodes at each level of the tree (maybe in an array).
    I have no trouble writing an algorithm that does a breadth-first traversal, but I have lots of trouble trying to determine where each level ends.
    Thanks for the help

    Try something like this:
    class BTree {
        BTreeNode root;
        public int numberOfNodesAtLevel(int level) {
            if(root == null) return -1;
            return numberOfNodesAtLevel(root, level);
        private int numberOfNodesAtLevel(BTreeNode node, int level) {
            if(level == 0) {
                return 1;
            } else {
                return (node.left  == null ? 0 : numberOfNodesAtLevel(node.left, level-1)) +
                       (node.right == null ? 0 : numberOfNodesAtLevel(node.right,level-1));
    }

  • Conversion of Binary to Text

    Hi,
    I am facing a problem while converting data from Binary to Text format, I've used FM SCMS_BINARY_TO_TEXT but still there is no Output.
    Can any1 please tell a FM which does the conversion??
    Cheers
    Abhishek

    FUNCTION MODULES
    http://www.erpgenie.com/abap/functions.htm
    http://www.sapdevelopment.co.uk/fmodules/fmssap.htm
    http://www.erpgenie.com/abap/index.htm
    http://www.geocities.com/victorav15/sapr3/abapfun.html

  • Conversion int - binary

    Hello everybody,
    i want to change an integer signed value (on 32 bits) in binary format and do the reverse operation.
    So i wrote :
    String binIntStr = Integer.toBinaryString(-1610612462);
    System.out.println("Binary : "+binIntStr);
    System.out.println("Int : "+Integer.parseInt(binIntStr, 2));The conversion of the int to binary runs correctly, but the reverse operation (binary string to int) throws an NumberFormatException.
    I don't understand why the operation is well done in one way and is not allowed in the other.
    The integer value is in good format (-2147483648 < -1610612462 < 2147483647) so why can't I change the binary string returned by the method toBinaryString in an integer ?

    Integer.toBinaryString() returns a string representation of the integer argument as an unsigned integer in base 2
    from the API doc
    toBinaryString
    public static String toBinaryString(int i)Returns a string representation of the integer argument as an unsigned integer in base 2.
    The unsigned integer value is the argument plus 232 if the argument is negative; otherwise it is equal to the argument.
    This value is converted to a string of ASCII digits in binary (base 2) with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero character '0' ('\u0030');
    otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.
    Parameters:
    i - an integer to be converted to a string.
    Returns:
    the string representation of the unsigned integer value represented by the argument in binary (base 2).so you will have to figure out out to deal with signed values yourself
    Message was edited by:
    SomeoneElse

  • Conversion of microseconds to number of days in OSB

    Hi All,
    I want to convert a string variable (e.g1245677889) which represents microseconds.I want to convert this microseconds to corresponding number of days in OSb.I there any xquery function that can be directly used to get the number of days????
    thanks in advance!!!!

    Thanks for the reply.
    I have already done that,But my requirement is to get the corresponding date (with 1970-01-01 as the reference date).
    So i want something in date format on which i can apply some boilt in functions.
    Is there any way we can do increament of an date variable in OSB???
    that will also help if i can increase the date the number of times i get converting miliseconds to days(eg. if miliseconds=86400000 i have to increase the reference date once as 86400000 corresponds to 1 day only) .

  • Conversion of Date into Number of Days

    Hai All,
               Can anyone pls tell how to convert the Date format into Number of days.
    For example I have 2 dates, 25.03.2009 and 25.02.2009.
    I have to take the difference of these two dates, means its 30 days.
    Later I have to move this 30 days to a variable and display.
    Can anyone help me.

    Try these FMs.
    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
    EXPORTING
    i_datum_bis = p_sdate
    i_datum_von = p_edate
    IMPORTING
    e_tage = l_differ
    EXCEPTIONS
    days_method_not_defined = 1
    others = 2.
    WRITE:/ l_differ.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    exporting
    i_date_from = p_sdate
    i_date_to = p_edate
    I_FLG_SEPARATE = ' '
    IMPORTING
    E_DAYS = EDAYS
    E_MONTHS = EMONTHS
    E_YEARS = EYEARS.
    WRITE:/ No of Days ', EDAYS.
    Regards,
    Joan

  • Conversion error varchar2 to number

    Hi,
    I have a primary key "regnum", defined as varchar2(5). But all the values are numeric, however the number is positioned at the beginning of the varchar2-attribute.
    Example: 123bb in stead of bb123.
    In sql workshop I used the query "select from where regnum=:p2_regnum", give p2_regnum a value and no record is selected.
    With the query "select from where regnum = 2" a result is displayed.
    As a result (I assume it has the same reason) I can´t generate a form with report: selecting a record in the report, gives no record to fetch.
    How to solve?
    Any reaction will be appreciated.
    Leo

    Leo,
    Ok we can then walk through this and see if it is an issue of the data not being forwarded to your next page.
    On the page where the process is that selects the value do you have a branch to..
    If so then open this up and check to see that the Point (Branch Point) is set to On Submit: After Processing (After Computation, Validation, an Processing), check also the sequence number (let me know if there are other actions firing prior to this one). next check to ensure that the Action (Target Type) is page in this Application and that you do nto have (reset pagination for this page) selected. And that in the Conditions you have (-Select Condtion Type-) nothing needs to be selected.
    Also are you using a submit button or such to transfer the data from this page forward?
    After you have checked these items if it is still not working let me know.
    Randy

Maybe you are looking for