Libraryless. Click here for Pure Java version (73L/1K).
static int countDifferingBits(byte[] array1, byte[] array2) { int n = array1.length; int diff = 0; for i to n: diff += Int.bitCount(ubyteToInt(array1[i])^ubyteToInt(array2[i])); ret diff; } static int countDifferingBits(int[] array1, int[] array2) { int n = array1.length; int diff = 0; for i to n: diff += Int.bitCount(array1[i]^array2[i]); ret diff; } static int countDifferingBits(long[] array1, long[] array2) { int n = array1.length; int diff = 0; for i to n: diff += Long.bitCount(array1[i]^array2[i]); ret diff; } // use sub-array of array2 static int countDifferingBits(long[] array1, long[] array2, int i1) { int n = array1.length; int diff = 0; for i to n: diff += Long.bitCount(array1[i]^array2[i1+i]); ret diff; }
Began life as a copy of #1035863
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036047 |
Snippet name: | countDifferingBits - between 2 byte, int or long arrays |
Eternal ID of this version: | #1036047/4 |
Text MD5: | 23cfe248a6707ece5c899bc16f76da1d |
Transpilation MD5: | f033e894d7ce78c5a1dd0a9b9756c3f4 |
Author: | stefan |
Category: | javax / bit ops |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-09-03 02:51:02 |
Source code size: | 807 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 178 / 220 |
Version history: | 3 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |