Modulo-2 /exclusive OR binary division

I need to do binary division in Java. Basically, I have a data file that has a binary string in it, and I need to divide another binary string into it to perform a CRC check. I've been looking at a couple of operators, hoping that I can just supply them with the strings, rather than write my own algorithm. Can I just feed two strings to the "%" or "^" operators and get the results? The "^" operator looks the most promising, since it is for exclusive-OR functions, which this is. Otherwise I'll have to compare the strings bit-by-bit, and not have very much fun.

I had a bit of a look through your program. I can't offer you any complete solutions but I can point out a few places where your logic is failing.
For starters, bitwise operators work on integers and to convert a binary string to an integer you need to use parseInt(String s, int radix) instead of Integer.parseInt(String s). Radix is the base that the string is representing the number in, so you use 2 for a binary string. Otherwise parseInt is reading your binary string of 1011 as one thousand and eleven because it is assuming it is an integer. This problem is found in places like lines 129 -130 in your code. They need to be changed to:          genPolyInt = Integer.parseInt(genPoly, 2);
          transPolyInt = Integer.parseInt(transPoly, 2);Are you trying to print out a binary string just below these lines? Use this to return an integer as a binary string:crcString = Integer.toBinaryString(myCrc);I don't know much about CRC but I don't think you are implementing the check properly. Fix this up and you should be right.

Similar Messages

  • Setting area/territory to a customer

    We have three major divisions and we have three sales persons working for each division in a single area. Kindly suggest how to map this to a particular busines partner in a particular area. Thanks in advance

    This will depend on what you are wanting to track. I am assuming you have nine sales people (3 for each of 3 divisions?).
    Can you Business Partners deal with all divisions, or are they exclusive to one division? Are you wanting to report based on sales analysis type reporting, or do you want profit & loss reporting for each division?

  • Binary addition,subtraction and modulo operations.

    Query:
    Take two 512 bit numbers passed as strings. don't use biginteger!
    convert them to binary without using parseInt or toString functions.! you may use char array and byte arrays.
    then add these two binary numbers using binary addition logic.
    display the result in decimal format back again.
    Is it possible to perform this operation like this!!if yes,then please tell how should i approach with my existing code.
    thanks.
    package bytearrayopeations;
    import java.math.BigInteger;   
    public class binaryadding {
        public static void main(String[] args) {
            BigInteger a = new BigInteger("123456");
            BigInteger b = new BigInteger("5121");
            String bb1 = a.toString(2);
            String bb2 = b.toString(2);
            String ss1 = null;
            String ss2 = null;
            String result = "";
            String carry="0";
            System.out.println("first value=" +bb1);
            System.out.println("second value=" +bb2);
            int k=bb1.length();
            int h=bb2.length();
            System.out.println("length 1="+ k);
            System.out.println("length 2=" +h);
            int p=h-k;
            //System.out.println("difference=" +p);
            int q=k-h;
            //System.out.println("difference 2=" +q);
            if(h==k)
           else if(h>k)
                for(int i=0;i<p;i++)
                    bb1="0"+bb1;
                System.out.println("new value of first=" +bb1);   
        else if(h<k)
            for(int i=0;i<q;i++)
                bb2="0"+bb2;
            System.out.println("new value of second=" +bb2);
            StringBuffer sb1=new StringBuffer(bb1);
         StringBuffer sb2=new StringBuffer(bb2);
            bb1=sb1.reverse().toString();
         bb2=sb2.reverse().toString();
            //System.out.println("rev. buffer1=" +bb1);
            //System.out.println("rev. buffer2=" +bb2);
            for(int i=0;i<bb1.length();i++)
                ss1=bb1.substring(i,i+1);
                ss2=bb2.substring(i,i+1);
              System.out.println("value1=" + ss1 + "    " + "value2=" + ss2);
              if (ss1.equals("0") && ss2.equals("0")) 
                 if (carry.equals("0")) 
                     result+="0";
                        else
                            result+="1";
               else if (ss1.equals("1") && ss2.equals("1"))
                if (carry.equals("0")) 
                    result+="0";
              carry="1";
              else
                   result+="1";
                   carry="1";
        else if (ss1.equals("0") && ss2.equals("1"))
                     if (carry.equals("0")) 
                         result+="1";
                   carry="0";
                        else
                          result+="0";
                                    carry="1";
               else if (ss1.equals("1") && ss2.equals("0"))
                     if (carry.equals("0")) 
                        result+="1";
                        carry=" 0";
                   else
                                result+="0";
                                carry="1";
           System.out.println("sum=" +result + "         " + "carry" + carry);
                        result+=carry;
                        StringBuffer sb3=new StringBuffer(result);
                        result=sb3.reverse().toString();
                    System.out.println("result is " +result); 
                  System.out.println("Binary = "+ result + ", Decimal = "+Integer.parseInt(result,2));
    }

    bansal.s, you have been warned. I am now blocking your account for a month.

  • 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;

  • SFTP vs. ASCII/Binary distinction

    SFTP in Dreamweaver 8 does not, apparently, understand how to
    convert ASCII files from Windows (with CR LF line divisions) to
    Unix/Linux (LF line divisions). Non-secure FTP does, but that's a
    standard feature of the FTP protocol. Dreamweaver seems to just
    transfer ASCII file types in binary over SFTP, CR LF and all. So
    SFTP silently breaks .CGI files, which execute as shell scripts and
    won't run on Linux with CR LF line breaks. This can break your web
    site unexpectedly.
    (.HTML files work OK, because HTML format documents are
    indifferent to the CR LF / LF distinction. But that's not true of
    .CGI files.)
    Is there some workaround for this?

    John Nagle wrote:
    > shell scripts and won't run on Linux with CR LF line
    breaks. This can break
    > your web site unexpectedly.
    Edit > Preferences > Code Format. Select LF (Unix) as
    Line break type.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Binary Sytem / binary operation

    I need any references (websites/PDFs) explainning binary sytem and binary operations (conversion,subtraction,division..)
    thanx in advance

    hi,
    try these:
    http://mindprod.com/jglossbinary.html
    http://www.learnbinary.com/
    for the last one click start in the top banner to start the tutorial, it's shown in an applet so it might take time to load depending on your connection.

  • NI 9870 and binary coded decimal (BCD)

    I have a scale that outputs the weight in 4 digit ASCII form which I would like to input into a CompactRio 9072 with a NI 9870 card and convert to a binary integer. The weight appears as the 7th to 10th character on lines that are terminated by a CR. I am thinking I will need a loop that once the 10th character is read, the 4 least significant bits of the 4 characters are converted from BCD to binary and the character counter resets to 0 when a CR is read. I need a good method for converting BCD to an integer value in either labview or vhdl. The rest of the logic for this project is in vhdl, so I would not mind adding the conversion logic there, except that all the algorithms I have found require decimal division or comparison in several clock cycles.
    Solved!
    Go to Solution.

    Hello imr
    Thank you very much for getting in touch with us!
    I believe the following community example will resolve part of your issue.
    Binary String to Number
    https://decibel.ni.com/content/docs/DOC-11704
    I have also provided some further information for those unaware of what Binary Coded Decimal represents.
    What is Binary Coded Decimal (BCD)?
    http://digital.ni.com/public.nsf/allkb/59C2A05C123​008F286256CA90069A6F8
    Thank you for choosing National Instruments!
    Sincerely,
    Greg S.

  • Reading a multi-dimensional array from a binary file?

    Hi, experts!
    Once again I'm stuck with a basic problem in labview. I've ben trying to make a VI that reads a binary measurement file that consists of a 2D array, i.e. n channels of sampled data. This seems to be easier said than done in LV and I the only example I find treats 1D-arrays exclusively. Take a look at the test file attached to this message. I saved it as a labview 7.1 file.
    Eternally grateful for all help
    Einar
    Attachments:
    W&R binary array.vi ‏115 KB

    Your write operation results into 1000 consecutive values written on disk without any array length indication. You can't read that data directly into a 2D array because the sizes are unknown to the Read function. You should read the whole file into a 1D array and the reshape the array into a 500 by 2 array. See the pict to figure how the Read/Write operations perform on arrays.
    Message Edité par JeanPierre le 03-14-2006 09:00 AM
    LabVIEW, C'est LabVIEW
    Attachments:
    Example_BD.png ‏18 KB

  • I need one Customer with a credit limit split between internal divisions

    We have a company code, with no active Business Areas. We have 6 operating divisions within the Co. code split by Sales Organisations. Some divisions share the same customers. Each division wants its own exclusive credit limit.
    We want one customer to have one master credit limit with the ability to split the limit between divisions. SAP seems only to allow 1 company code/credit limit/customer.
    Any ideas if it is possible to do this? Reasons why this is not possible would be appreciated as well.
    Thanks for your help and suggestions, Dave

    <a href="https://forums.sdn.sap.com/click.jspa?searchID=6068311&messageID=3895125">Refer here!</a>
    <a href="http://help.sap.com/erp2005_ehp_02/helpdata/en/4d/0a4aa6b26811d194f400a0c9306794/content.htm">Additional documentation relevant to assigining Sales area (sales organization, distribution channel, division) Enterprise Structure > Assignment > Sales and Distribution > Assign sales area to credit control area</a>

  • Java(TM) Platform SE binary doesn't work on any website, on any browser

    I'm on Windows 7 Ultimate 32bit, everything's working fine, I always keep my system clean, I also keep the registry as clean as possible, I have a problem from at least a couple of months, so "Java(TM) Platform SE binary" doesn't work on any website, on any browser, it always crash, I tried everything, I mean EVERYTHING! I've uninstalled and re-installed java a thousand of times, completely uninstalled, removed all files, all registry entries, nothing seems to work..I always get the same message..
    here's the error signature:
    Firma problema:
      Nome evento problema: BEX
      Nome applicazione: java.exe
      Versione applicazione: 7.0.400.43
      Timestamp applicazione: 521c3bf2
      Nome modulo con errori: ntdll.dll
      Versione modulo con errori: 6.1.7600.16385
      Timestamp modulo con errori: 4a5bdadb
      Offset eccezione: 0001d78d
      Codice eccezione: c0000409
      Dati eccezione: 00000000
      Versione SO: 6.1.7600.2.0.0.256.1
      ID impostazioni locali: 1040
      Informazioni aggiuntive 1: a091
      Ulteriori informazioni 2: a0912fac5db1285ab245a51982c0da6c
      Ulteriori informazioni 3: 0ef4
      Ulteriori informazioni 4: 0ef461fa84dd27e3340858dc9ed3bcb3
    and here's a video (made by me) of the problem: Java(TM) Platform SE binary stopped working - YouTube
    can anyone help me find a solution?
    Thanks

    Looks like you have conflict with your java home and you are running 2 different JREs. Keep the latest and try launching EM console again and post the exception if you get any.
    Thanks,
    Vijay

  • SD-Exclusion

    hi,
    In which kind of scenario we will be going for Exclusion in Condition type creation.
    Thanks

    Hi Ganesh,
    I can give a small ex of what we have done:
    If product belongs to a particular division then we have to calculate the price based ob Gross Weight. But when it belongs to any other division then frieght is calculated on % basis.
    We already had a pricing procedure and frieght condition type in place. so to fulfill this requirement, we add a condition Type for frieght calculation on Gross weight and then made this a group condtion with the already existing Frieght condition type using a special requirement.
    Hope this provides some understanding.
    Reward if it helps
    Regards
    Srini

  • Finding the remainder of a division

    Hi.
    I want to do a division in actionscript, say 49/2 and I want
    to return 2 variables - the integer that goes into 49 twice=24 and
    the remainder- 1. I also want this to return a remainder of 0 if
    there is no remainder.
    I'm just a little stuck on the code i'd use.
    Thanks in advance,
    Mac

    How about Number.toString(radix):
    var n:Number = 49;
    trace(n.toString(2));
    trace(n.toString(8));
    trace(n.toString(16));
    "mac monkey" <[email protected]> wrote in
    message
    news:e9ea08$ovc$[email protected]..
    > Yes I actually I was trying to convert a number to
    binary using that
    > method..the one found here:
    >
    >
    http://www.janeg.ca/scjp/oper/binhex.html
    >
    > However, I've since realised for what I'm doing hex
    would be more
    > suitable. I
    > was going to use 49/16 instead of 49/2..but you say that
    method is wrong?
    > any
    > help greatly appreciated.
    >
    > Ta,
    > mac
    >

  • Compare of double after division

    HI!
    Plese see attached VI. I divide two doubles and compare the result with another double. This works for low numbers but if the result of the division is for example 1000.00 (4.5/4.5e-3)the greater as function (compared with 1000.00) provides true at the output. Has it something to do with the internal rounding, representation of the doubles? Or how LV performs the division?
    How can I get the right response from the greater as function?
    ANDY
    Attachments:
    greater.vi ‏20 KB

    It is the conversion of floating point numbers to binary representation that computers understand and the problem is present in all programming languages. Comparison of floating point numbers is something that should be avoided. There is a discussion of this on the LabVIEW FAQ. Select the Front Panel subforum and the "Why does my output show -0.99 .." and "So how do I .." topics.

  • Selection exclusions not considered in statistical forecasting

    HI,
    Our planning object structure has total 6 characteristics and some of them are product, location, division and region. Product has product class as a navigational attribute.
    We have created 2 selection ids in planning book.
    id1: display "division" and entered some divisions and excluded some regions and product class
    id2: display "division" and entered some divisions and excluded some regions.
    When we ran statistical forecasting, the statistical models ( moving average model used but we tried other models too) the system is still forecasting for the excluded selections in planning books.
    Here are my questions:
    1. In case of id1 since there is a navigational attribute, can we use navigational attributes in statistical forecasting.? I remember not but not totally sure...any supporting documentation or references are helpful.
    2. In case of id2, I can not imagine why the excluded values are forecasted..even the POS  characteristic value exclusions are ignored. I think this is a bug...did any one see this kind of behavior? any suggestions or OSS notes are appreciated.
    Thanks.

    Hi,
    Your aggregation level explains your results.
    What is happening is that based on your selection criteria, divisions are getting selected.
    Since your aggregation level is division, hence for whatever divisions have got selected as per your selection criteria, forecasting would be done based on history aggregated at division level. Now it doesn't matter whether you maintained exclusions at any other level or not.
    Result would be forecast for the selected divisions at an aggregated level. Now, this forecast would get disaggregated to ALL the CVCs which contain these selected divisions, and the disaggregation would happen as per the calculation type that you maintained for the stat forecast.
    If you don't want the forecast to be disaggregated to levels below division, then do the forecast at a lower level of aggregation, meaning select all the characteristics in "aggregation" corresponding to the levels which you want to exclude.
    Hope this explains the situation to you.
    One way you can say that the "display" characteristic (topmost row) that you specify in selection when you load data in interactive planning corresponds to the aggregation level that you maintain in background.
    Thanks - Pawan

  • Exclusive Access To The Database

    Is there a way for my code to know if I have
    Exclusive Access To The Database?  If so, what would the
    Compress Database Command be?
    Application:  I would like my update script to include a command to compress the database, when no one else is in the database.

    Hi Mark,
    >> Is there a way for my code to know if I have Exclusive Access To The Database?
    I think you could check whether the Access is exclusive with vba code, some key code as below:
    Function IsCurDBExclusive () As Integer
    ' Purpose: Determine if the current database is open exclusively.
    ' Returns: 0 if database is not open exclusively.
    ' -1 if database is open exclusively.
    ' Err if any error condition is detected.
    Dim db As Database
    Dim hFile As Integer
    hFile = FreeFile
    Set db = dbengine.workspaces(0).databases(0)
    If Dir$(db.name) <> "" Then
    On Error Resume Next
    Open db.name For Binary Access Read Write Shared As hFile
    Select Case Err
    Case 0
    IsCurDBExclusive = False
    Case 70
    IsCurDBExclusive = True
    Case Else
    IsCurDBExclusive = Err
    End Select
    Close hFile
    On Error GoTo 0
    Else
    MsgBox "Couldn't find " & db.name & "."
    End If
    End Function
    For more information, you could turn to the link below:
    # ACC: How to Determine If a Database Is Open Exclusively
    http://support.microsoft.com/kb/117539
    >> If so, what would the Compress Database Command be?
    For compressing the database, I think you could use
    # Application.CompactRepair Method (Access)​
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

Maybe you are looking for