Any quick way to count the number of bits in a bitNetwork other than the usual method of "keeping a counter"?
The cardinality () method returns the number of bits set.
(Assuming you don't want to call power ())
int count = 0; for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) { count++; }
see javadoc
BitSet B1 = new BitSet(3); B1.set(0); B1.cardinality();
Output:
1
Source: https://habr.com/ru/post/1338209/More articles:Bash create a variable and then assign a value to it - linuxhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1338205/how-to-add-months-to-the-date-without-calendar&usg=ALkJrhi5k7x42yZqfe-VMb7oXuz4i7e1RAhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1338206/cannot-open-database-aspnetdb-requested-by-the-login-the-login-failed-login-failed-for-user-philip-desktopphilip&usg=ALkJrhg5HoYvjD907uTc_BfZNSxeIyyhhwHow to set CheckBox.IsChecked based on the existence of a linked object in a list - checkboxHow to determine the OpenID username when the identifier does not have a username? - openidWhat is the difference between EditText and AutoCompleteTextView in Android? - androidSpeech to text in Windows Phone 7 - windows-phone-7Registration Package Guidelines for R - rdeploy Android application on a real device - androidDisabling past dates in datapicker wpf is possible - wpfAll Articles