Here you can find the source of norm(byte[] tab)
Parameter | Description |
---|---|
tab | a parameter |
public static short norm(byte[] tab)
//package com.java2s; //License from project: Open Source License public class Main { /**//w w w .j ava2 s . co m * Computes the number of 1's in the byte array * @param tab * @return */ public static short norm(byte[] tab) { short count = 0; for (byte b : tab) { count += bitCount(b); } return count; } /** * Hamming distance of a byte with 0 * @param b the byte on which we compute the hamming distance with 0 * @return the number of 1's in the binary representation of the byte */ public static short bitCount(byte b) { short temp = (short) (b + 128); short count = 0; for (int i = 0; i < 8; i++) { count += (temp >> (7 - i)) % 2; } return count; } }