v.0.0.8 mv number_to_bitarray_msb in utils-mathematics

This commit is contained in:
tiijay
2025-11-05 17:23:42 +01:00
parent b7f5e924e0
commit 7bdd67f3c3
6 changed files with 66 additions and 46 deletions

7
lib/Utils/library.json Normal file
View File

@@ -0,0 +1,7 @@
{
"name": "BlinkLed",
"version": "1.0.0",
"description": "A simple LED control library with internal LED helper.",
"authors": [{ "name": "TiiJay14" }],
"frameworks": "arduino"
}

View File

@@ -0,0 +1,30 @@
#include "mathematics.h"
vector<uint16_t> number_to_bitarray_msb(u_int16_t number, int bits, boolean four_bits)
{
Serial.printf("s-o-n: %d", sizeof(number));
Serial.println();
/** Convert 8/16-bit number to bit array (MSB first) */
std::vector<uint16_t> two_bytes;
two_bytes.reserve(bits);
for (int i = bits - 1; i >= 0; i--)
{
two_bytes.push_back((number >> i) & 1);
}
// Debug, Ausgabe des Bytes
Serial.printf("[0x%04X] ", number);
uint8_t idx = 0;
for (auto bit : two_bytes)
{
Serial.printf("%d", bit);
idx++;
if (four_bits && !(idx % 4))
Serial.printf(" ");
}
Serial.println();
return two_bytes;
}

View File

@@ -0,0 +1,11 @@
#ifndef MATHEMATICS_H
#define MATHEMATICS_H
#include <Arduino.h>
#include <vector>
using namespace std;
vector<uint16_t> number_to_bitarray_msb(uint16_t number, int bits = 16, boolean four_bits = false);
#endif