v.0.0.8 mv number_to_bitarray_msb in utils-mathematics
This commit is contained in:
7
lib/Utils/library.json
Normal file
7
lib/Utils/library.json
Normal 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"
|
||||
}
|
||||
30
lib/Utils/src/mathematics.cpp
Normal file
30
lib/Utils/src/mathematics.cpp
Normal 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;
|
||||
}
|
||||
11
lib/Utils/src/mathematics.h
Normal file
11
lib/Utils/src/mathematics.h
Normal 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
|
||||
Reference in New Issue
Block a user