mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-03-28 17:42:59 +01:00
23 lines
371 B
C
23 lines
371 B
C
#include <Arduino.h>
|
|
|
|
String toBinary(int num, int bitSize)
|
|
{
|
|
if (num == 0)
|
|
return "0";
|
|
|
|
String binary = "";
|
|
while (num > 0)
|
|
{
|
|
binary = String(num % 2) + binary;
|
|
num /= 2;
|
|
}
|
|
|
|
// Pad with leading zeros to match `bitSize`
|
|
while (binary.length() < bitSize)
|
|
{
|
|
binary = "0" + binary;
|
|
}
|
|
|
|
return binary;
|
|
}
|