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).

static int bitCount(BitSet bs) {
  ret bs == null ? 0 : bs.cardinality();
}

static int bitCount(int i) {
  ret Integer.bitCount(i);
}

static int bitCount(byte[] array) {
  if (array == null) ret 0;
  int sum = 0;
  for (b : array)
    sum += bitCount(ubyteToInt(b));
  ret sum;
}

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: 364 / 460
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)