Tag

Bit

Browsing

Write a program to count the set bits in byte arrays. source Code package com.dsacode.Algorithm.bit; public class CountingSet { public CountingSet(){ preCalculate(); } public int countBits1(int num){ int count=0; while(num > 0){ num &= num-1; count++; } return count; } private int count[] = new int[256]; void preCalculate(){ for(int i=0; i < 256; i++){ count[i] = countBits1(i); } } public int countBits2(int num){ int total = 0; int mask = (1 << 8) – 1; for(int i=0 ; i < 4; i++){ total += count[num & mask]; num = num >>> 8; } return total; } public static void main(String…

Little endian and big endian are ways to store multi-byte data types. Little endian store the last byte of binary representation of the multibyte store first. The big endian store first byte of binary representation of the multibyte store first.