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
github: RobTillaart
custom: "https://www.paypal.me/robtillaart"

View File

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

View File

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

View File

@ -9,10 +9,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
uses: limitusus/json-syntax-check@v2
with:
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/)
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
- update readme.md
## [0.1.10] - 2023-02-08
- reorganize readme.md
- update GitHub actions

View File

@ -1,6 +1,6 @@
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
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.
#### Related
- https://github.com/RobTillaart/BitArray
## Interface
```cpp
@ -70,18 +75,18 @@ swap upper and lower half: uint8_t .. uint64_t. Is like rotate 50%
#### BitRotate
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 bitRotateRight(T value, uint8_t pos)**
- **T bitRotateLeft(T value, uint8_t position)**
- **T bitRotateRight(T value, uint8_t position)**
#### BitFlip
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
@ -134,7 +139,7 @@ Also added are macro versions of these five functions.
#### Should
- add performance tests
- **bitRotateLeftRight()** should it do modulo pos?
- **bitRotateLeftRight()** should it do modulo position?
- **bitsNeededRef()** correct for value 0?
- **nybbleReverse()** => **nibbleReverse()**
@ -151,7 +156,8 @@ specific position. e.g.
- **bitSort(value)** 00101001 ==> 00000111
or with minimal # toggles?
- **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 ~?
- **isBitPalindrome()** byte, word ...
- **bitSwap(value, p, q)**
@ -161,7 +167,6 @@ or with minimal # toggles?
#### Wont
## ideas
#### BitReverse n bit number

View File

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

View File

@ -2,7 +2,7 @@
//
// FILE: bitHelpers.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.11
// VERSION: 0.1.12
// DATE: 2015-11-07
// PURPOSE: Arduino library with functions on bit level
// URL: https://github.com/RobTillaart/bitHelpers
@ -11,7 +11,7 @@
#include "Arduino.h"
#define BITHELPER_LIB_VERSION (F("0.1.11"))
#define BITHELPER_LIB_VERSION (F("0.1.12"))
// used by bitRot()
@ -110,39 +110,39 @@ uint64_t swap(uint64_t value);
//
// 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
//
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
//
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)
// URL: https://github.com/RobTillaart/bitHelpers
#include "bitHelpers.h"
uint32_t start, stop;
@ -20,6 +21,7 @@ void setup()
test64();
}
void test8()
{
Serial.println();
@ -47,6 +49,7 @@ void test8()
delay(10);
}
void test16()
{
Serial.println();
@ -74,6 +77,7 @@ void test16()
delay(10);
}
void test32()
{
Serial.println();
@ -101,6 +105,7 @@ void test32()
delay(10);
}
void test64()
{
Serial.println();

View File

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

View File

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

View File

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