Java Bitwise XOR bitDifference(String s1, String s2)

Here you can find the source of bitDifference(String s1, String s2)

Description

bit Difference

License

Open Source License

Declaration

public static final int bitDifference(String s1, String s2) 

Method Source Code

//package com.java2s;
/*//from   w ww. ja va  2 s  .c  om
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static final int bitDifference(String s1, String s2) {
        int sum = 0;
        for (int i = 0; i < s1.length(); i++) {
            if (s1.charAt(i) != s2.charAt(i))
                sum++;
        }
        return sum;
    }

    public static final int bitDifference(String y1[], String y2[]) {
        int sum = 0;
        for (int i = 0; i < y1.length; i++) {
            if (!y1[i].equals(y2[i]))
                sum++;
        }
        return sum;
    }

    public static final int bitDifference(int y1[], int y2[]) {
        int sum = 0;
        for (int i = 0; i < y1.length; i++) {
            if (y1[i] != y2[i])
                sum++;
        }
        return sum;
    }
}

Related

  1. bitXor(Byte a, Byte b)
  2. bitXor(Long a, Long b)