0.1.12 bitHelpers

This commit is contained in:
Rob Tillaart 2024-04-09 16:49:37 +02:00
parent c160daa034
commit 2e4eb500c8
16 changed files with 105 additions and 82 deletions

View File

@ -1,4 +1,5 @@
# These are supported funding model platforms # These are supported funding model platforms
github: RobTillaart github: RobTillaart
custom: "https://www.paypal.me/robtillaart"

View File

@ -1,12 +1,12 @@
name: Arduino-lint name: Arduino-lint
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 5
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1 - uses: arduino/arduino-lint-action@v1
with: with:
library-manager: update library-manager: update

View File

@ -1,4 +1,3 @@
---
name: Arduino CI name: Arduino CI
on: [push, pull_request] on: [push, pull_request]
@ -6,9 +5,10 @@ on: [push, pull_request]
jobs: jobs:
runTest: runTest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 20
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1
with: with:
ruby-version: 2.6 ruby-version: 2.6

View File

@ -9,10 +9,11 @@ on:
jobs: jobs:
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 5
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: json-syntax-check - name: json-syntax-check
uses: limitusus/json-syntax-check@v1 uses: limitusus/json-syntax-check@v2
with: with:
pattern: "\\.json$" pattern: "\\.json$"

View File

@ -5,10 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.12] - 2024-04-09
- update GitHub actions
- update keywords.txt
- minor edits
## [0.1.11] - 2023-10-18 ## [0.1.11] - 2023-10-18
- update readme.md - update readme.md
## [0.1.10] - 2023-02-08 ## [0.1.10] - 2023-02-08
- reorganize readme.md - reorganize readme.md
- update GitHub actions - update GitHub actions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2015-2023 Rob Tillaart Copyright (c) 2015-2024 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -27,6 +27,11 @@ If they don't please file an issue on GitHub.
New bit functions can be added or investigated, please file an issue on GitHub. New bit functions can be added or investigated, please file an issue on GitHub.
#### Related
- https://github.com/RobTillaart/BitArray
## Interface ## Interface
```cpp ```cpp
@ -70,18 +75,18 @@ swap upper and lower half: uint8_t .. uint64_t. Is like rotate 50%
#### BitRotate #### BitRotate
Rotate Left / Right: uint8_t .. uint64_t Rotate Left / Right: uint8_t .. uint64_t
if pos larger than # bits original value is returned. if position larger than # bits original value is returned.
- **T bitRotateLeft(T value, uint8_t pos)** - **T bitRotateLeft(T value, uint8_t position)**
- **T bitRotateRight(T value, uint8_t pos)** - **T bitRotateRight(T value, uint8_t position)**
#### BitFlip #### BitFlip
BitFlip: uint8_t .. uint64_t a.k.a toggle BitFlip: uint8_t .. uint64_t a.k.a toggle
if pos larger than # bits original value is returned. if position larger than # bits original value is returned.
- **T bitFlip(T value, uint8_t pos)** flips a single bit at pos - **T bitFlip(T value, uint8_t position)** flips a single bit at position
#### BitRot #### BitRot
@ -134,7 +139,7 @@ Also added are macro versions of these five functions.
#### Should #### Should
- add performance tests - add performance tests
- **bitRotateLeftRight()** should it do modulo pos? - **bitRotateLeftRight()** should it do modulo position?
- **bitsNeededRef()** correct for value 0? - **bitsNeededRef()** correct for value 0?
- **nybbleReverse()** => **nibbleReverse()** - **nybbleReverse()** => **nibbleReverse()**
@ -151,7 +156,8 @@ specific position. e.g.
- **bitSort(value)** 00101001 ==> 00000111 - **bitSort(value)** 00101001 ==> 00000111
or with minimal # toggles? or with minimal # toggles?
- **bitReverse(uint32_t x, uint8_t n)** see below. - **bitReverse(uint32_t x, uint8_t n)** see below.
- **byteReverse24(uint32_t x)** dedicated 24 bit = 3 bytes e.g RGB - **byteReverse24(uint32_t x)** dedicated 24 bit = 3 bytes e.g RGB ==> BGR
- **byteRotate24(uint32_t x)** dedicated 24 bit = 3 bytes e.g RGB
- **byteInverse(uint32_t x)** (a,b,c,d) => (255-a, 255-b, 255-c, 255-d) = rather simple ~? - **byteInverse(uint32_t x)** (a,b,c,d) => (255-a, 255-b, 255-c, 255-d) = rather simple ~?
- **isBitPalindrome()** byte, word ... - **isBitPalindrome()** byte, word ...
- **bitSwap(value, p, q)** - **bitSwap(value, p, q)**
@ -161,7 +167,6 @@ or with minimal # toggles?
#### Wont #### Wont
## ideas ## ideas
#### BitReverse n bit number #### BitReverse n bit number

View File

@ -1,7 +1,7 @@
// //
// FILE: bitHelpers.cpp // FILE: bitHelpers.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.11 // VERSION: 0.1.12
// DATE: 2015-11-07 // DATE: 2015-11-07
// PURPOSE: Arduino library with functions on bit level // PURPOSE: Arduino library with functions on bit level
// URL: https://github.com/RobTillaart/bitHelpers // URL: https://github.com/RobTillaart/bitHelpers
@ -309,35 +309,35 @@ uint64_t swap(uint64_t value)
// //
// BIT ROTATE LEFT // BIT ROTATE LEFT
// //
uint8_t bitRotateLeft(uint8_t value, uint8_t pos) uint8_t bitRotateLeft(uint8_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 7) return value; if (position > 7) return value;
return (value << pos) | (value >> (8 - pos)); return (value << position) | (value >> (8 - position));
} }
uint16_t bitRotateLeft(uint16_t value, uint8_t pos) uint16_t bitRotateLeft(uint16_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 15) return value; if (position > 15) return value;
return (value << pos) | (value >> (16 - pos)); return (value << position) | (value >> (16 - position));
} }
uint32_t bitRotateLeft(uint32_t value, uint8_t pos) uint32_t bitRotateLeft(uint32_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 31) return value; if (position > 31) return value;
return (value << pos) | (value >> (32 - pos)); return (value << position) | (value >> (32 - position));
} }
uint64_t bitRotateLeft(uint64_t value, uint8_t pos) uint64_t bitRotateLeft(uint64_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 63) return value; if (position > 63) return value;
return (value << pos) | (value >> (64 - pos)); return (value << position) | (value >> (64 - position));
} }
@ -345,35 +345,35 @@ uint64_t bitRotateLeft(uint64_t value, uint8_t pos)
// //
// BIT ROTATE RIGHT // BIT ROTATE RIGHT
// //
uint8_t bitRotateRight(uint8_t value, uint8_t pos) uint8_t bitRotateRight(uint8_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 7) return value; if (position > 7) return value;
return (value << (8 - pos)) | (value >> pos); return (value << (8 - position)) | (value >> position);
} }
uint16_t bitRotateRight(uint16_t value, uint8_t pos) uint16_t bitRotateRight(uint16_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 15) return value; if (position > 15) return value;
return (value << (16 - pos)) | (value >> pos); return (value << (16 - position)) | (value >> position);
} }
uint32_t bitRotateRight(uint32_t value, uint8_t pos) uint32_t bitRotateRight(uint32_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 31) return value; if (position > 31) return value;
return (value << (32 - pos)) | (value >> pos); return (value << (32 - position)) | (value >> position);
} }
uint64_t bitRotateRight(uint64_t value, uint8_t pos) uint64_t bitRotateRight(uint64_t value, uint8_t position)
{ {
if (pos == 0) return value; if (position == 0) return value;
if (pos > 63) return value; if (position > 63) return value;
return (value << (64 - pos)) | (value >> pos); return (value << (64 - position)) | (value >> position);
} }
@ -381,31 +381,31 @@ uint64_t bitRotateRight(uint64_t value, uint8_t pos)
// //
// BIT FLIP // BIT FLIP
// //
uint8_t bitFlip(uint8_t value, uint8_t pos) uint8_t bitFlip(uint8_t value, uint8_t position)
{ {
if (pos > 7) return value; if (position > 7) return value;
return value ^ (1 << pos); return value ^ (1 << position);
} }
uint16_t bitFlip(uint16_t value, uint8_t pos) uint16_t bitFlip(uint16_t value, uint8_t position)
{ {
if (pos > 15) return value; if (position > 15) return value;
return value ^ (1 << pos); return value ^ (1 << position);
} }
uint32_t bitFlip(uint32_t value, uint8_t pos) uint32_t bitFlip(uint32_t value, uint8_t position)
{ {
if (pos > 31) return value; if (position > 31) return value;
return value ^ (1UL << pos); return value ^ (1UL << position);
} }
uint64_t bitFlip(uint64_t value, uint8_t pos) uint64_t bitFlip(uint64_t value, uint8_t position)
{ {
if (pos > 63) return value; if (position > 63) return value;
return value ^ (1ULL << pos); return value ^ (1ULL << position);
} }

View File

@ -2,7 +2,7 @@
// //
// FILE: bitHelpers.h // FILE: bitHelpers.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.11 // VERSION: 0.1.12
// DATE: 2015-11-07 // DATE: 2015-11-07
// PURPOSE: Arduino library with functions on bit level // PURPOSE: Arduino library with functions on bit level
// URL: https://github.com/RobTillaart/bitHelpers // URL: https://github.com/RobTillaart/bitHelpers
@ -11,7 +11,7 @@
#include "Arduino.h" #include "Arduino.h"
#define BITHELPER_LIB_VERSION (F("0.1.11")) #define BITHELPER_LIB_VERSION (F("0.1.12"))
// used by bitRot() // used by bitRot()
@ -110,39 +110,39 @@ uint64_t swap(uint64_t value);
// //
// BIT ROTATE LEFT // BIT ROTATE LEFT
// //
uint8_t bitRotateLeft(uint8_t value, uint8_t pos); uint8_t bitRotateLeft(uint8_t value, uint8_t position);
uint16_t bitRotateLeft(uint16_t value, uint8_t pos); uint16_t bitRotateLeft(uint16_t value, uint8_t position);
uint32_t bitRotateLeft(uint32_t value, uint8_t pos); uint32_t bitRotateLeft(uint32_t value, uint8_t position);
uint64_t bitRotateLeft(uint64_t value, uint8_t pos); uint64_t bitRotateLeft(uint64_t value, uint8_t position);
//////////////////////////////////////////////// ////////////////////////////////////////////////
// //
// BIT ROTATE RIGHT // BIT ROTATE RIGHT
// //
uint8_t bitRotateRight(uint8_t value, uint8_t pos); uint8_t bitRotateRight(uint8_t value, uint8_t position);
uint16_t bitRotateRight(uint16_t value, uint8_t pos); uint16_t bitRotateRight(uint16_t value, uint8_t position);
uint32_t bitRotateRight(uint32_t value, uint8_t pos); uint32_t bitRotateRight(uint32_t value, uint8_t position);
uint64_t bitRotateRight(uint64_t value, uint8_t pos); uint64_t bitRotateRight(uint64_t value, uint8_t position);
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// //
// BIT FLIP // BIT FLIP
// //
uint8_t bitFlip(uint8_t value, uint8_t pos); uint8_t bitFlip(uint8_t value, uint8_t position);
uint16_t bitFlip(uint16_t value, uint8_t pos); uint16_t bitFlip(uint16_t value, uint8_t position);
uint32_t bitFlip(uint32_t value, uint8_t pos); uint32_t bitFlip(uint32_t value, uint8_t position);
uint64_t bitFlip(uint64_t value, uint8_t pos); uint64_t bitFlip(uint64_t value, uint8_t position);
//////////////////////////////////////////////////// ////////////////////////////////////////////////////

View File

@ -3,6 +3,7 @@
// PURPOSE: performance comparison (~30% faster) // PURPOSE: performance comparison (~30% faster)
// URL: https://github.com/RobTillaart/bitHelpers // URL: https://github.com/RobTillaart/bitHelpers
#include "bitHelpers.h" #include "bitHelpers.h"
uint32_t start, stop; uint32_t start, stop;
@ -20,6 +21,7 @@ void setup()
test64(); test64();
} }
void test8() void test8()
{ {
Serial.println(); Serial.println();
@ -47,6 +49,7 @@ void test8()
delay(10); delay(10);
} }
void test16() void test16()
{ {
Serial.println(); Serial.println();
@ -74,6 +77,7 @@ void test16()
delay(10); delay(10);
} }
void test32() void test32()
{ {
Serial.println(); Serial.println();
@ -101,6 +105,7 @@ void test32()
delay(10); delay(10);
} }
void test64() void test64()
{ {
Serial.println(); Serial.println();
@ -134,4 +139,4 @@ void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -439,5 +439,5 @@ void test_bitRot()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -76,5 +76,5 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -104,4 +104,4 @@ void printHex32(uint32_t x)
// -- END OF FILE -- // -- END OF FILE --

View File

@ -5,6 +5,10 @@
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
bitCountReference KEYWORD2 bitCountReference KEYWORD2
bitCountKR KEYWORD2
bitCountArray KEYWORD2
bitCountF1 KEYWORD2
bitCountF2 KEYWORD2
bitCount KEYWORD2 bitCount KEYWORD2
bitReverse KEYWORD2 bitReverse KEYWORD2
@ -17,6 +21,7 @@ bitRotateLeft KEYWORD2
bitRotateRight KEYWORD2 bitRotateRight KEYWORD2
bitFlip KEYWORD2 bitFlip KEYWORD2
bitRotRef KEYWORD2
bitRot KEYWORD2 bitRot KEYWORD2
bitSet64 KEYWORD2 bitSet64 KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/bitHelpers.git" "url": "https://github.com/RobTillaart/bitHelpers.git"
}, },
"version": "0.1.11", "version": "0.1.12",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=bitHelpers name=bitHelpers
version=0.1.11 version=0.1.12
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library with functions on bit level sentence=Arduino library with functions on bit level