Bit counting functions (CountBits, CountBits64) (#232)

* Core: CountBits and CountBits64 functions are added.

* autotest: CountBits test added.

* Core: inline force on CountBits and CountBits64
This commit is contained in:
İsmail Yılmaz 2025-02-14 21:25:25 +03:00 committed by GitHub
parent c4283f3ceb
commit 421eb73ac9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 112 additions and 0 deletions

View file

@ -0,0 +1,33 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
DUMP(CountBits(0x0001));
DUMP(CountBits(0x000f));
DUMP(CountBits(0x00ff));
DUMP(CountBits(0x0fff));
DUMP(CountBits(0xffff));
DUMP(CountBits(0x000fffff));
DUMP(CountBits(0x00ffffff));
DUMP(CountBits(0x0fffffff));
DUMP(CountBits(0xffffffff));
LOG("====================");
DUMP(CountBits64(0x00000001ffffffff));
DUMP(CountBits64(0x0000000fffffffff));
DUMP(CountBits64(0x000000ffffffffff));
DUMP(CountBits64(0x00000fffffffffff));
DUMP(CountBits64(0x0000ffffffffffff));
DUMP(CountBits64(0x000fffffffffffff));
DUMP(CountBits64(0x00ffffffffffffff));
DUMP(CountBits64(0x0fffffffffffffff));
DUMP(CountBits64(0xffffffffffffffff));
CheckLogEtalon();
}

View file

@ -0,0 +1,10 @@
uses
Core;
file
Etalon.log,
CountBits.cpp;
mainconfig
"" = "";

View file

@ -0,0 +1,21 @@
* /home/maldoror//upp/.cache/upp.out/autotest/CLANG.Debug.Debug_Full.Shared/CountBits 08.02.2025 14:47:07, user: maldoror
CountBits(0x0001) = 1
CountBits(0x000f) = 4
CountBits(0x00ff) = 8
CountBits(0x0fff) = 12
CountBits(0xffff) = 16
CountBits(0x000fffff) = 20
CountBits(0x00ffffff) = 24
CountBits(0x0fffffff) = 28
CountBits(0xffffffff) = 32
====================
CountBits64(0x00000001ffffffff) = 33
CountBits64(0x0000000fffffffff) = 36
CountBits64(0x000000ffffffffff) = 40
CountBits64(0x00000fffffffffff) = 44
CountBits64(0x0000ffffffffffff) = 48
CountBits64(0x000fffffffffffff) = 52
CountBits64(0x00ffffffffffffff) = 56
CountBits64(0x0fffffffffffffff) = 60
CountBits64(0xffffffffffffffff) = 64