Package hlcd.operations
Class HammingWeight
java.lang.Object
hlcd.operations.HammingWeight
A way to find the Hamming weight for vectors in base \(2\) or \(4\). The
approach uses the least amount of operations. The complexity is
\(\mathcal{O}(C)\) and without looping through the vector.
- Since:
- February 1st, 2022
- Version:
- 1.0
- Author:
- Maysara Al Jumaily
-
Constructor Summary
ConstructorsConstructorDescriptionHammingWeight(byte base)Creates a Hamming weight calculator ready in the base specified. -
Method Summary
-
Constructor Details
-
HammingWeight
public HammingWeight(byte base)Creates a Hamming weight calculator ready in the base specified.- Parameters:
base- the base of the code which could either be \(2\) or \(4\)
-
-
Method Details
-
getWeight
public byte getWeight(long vector)Returns the weight of the vector specified.- Parameters:
vector- the vector to find the weight of- Returns:
- the Hamming weight of the vector
-
getWeight
public static byte getWeight(long vector, byte base)Finds the weight of the vector in the base specified.- Parameters:
vector- the vector to find the weight ofbase- the base of the code which could either be \(2\) or \(4\)- Returns:
- the Hamming weight of the vector
-
getBase
public byte getBase()Returns the base the Hamming weight calculator is operating in.- Returns:
- the base of the code
-