Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #1019831 // bitCount - count set bits in BitSet, int or byte array

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (56L/1K).

1  
static int bitCount(BitSet bs) {
2  
  ret bs == null ? 0 : bs.cardinality();
3  
}
4  
5  
static int bitCount(int i) {
6  
  ret Integer.bitCount(i);
7  
}
8  
9  
static int bitCount(byte[] array) {
10  
  if (array == null) ret 0;
11  
  int sum = 0;
12  
  for (b : array)
13  
    sum += bitCount(ubyteToInt(b));
14  
  ret sum;
15  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019831
Snippet name: bitCount - count set bits in BitSet, int or byte array
Eternal ID of this version: #1019831/5
Text MD5: 2d6a634dfd22fd36476061820a000841
Transpilation MD5: 0af492a33b5142aa3cc1c37ad7a53296
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-23 15:04:51
Source code size: 295 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 365 / 462
Version history: 4 change(s)
Referenced in: [show references]