Byte Wert in String umwandeln

Umsetzen könnte man das wie folgt

constexpr byte MAX_LIST_INDEX {8};
constexpr byte MAX_BUFFER_SIZE{10}; // 8 Bitzeichen + 2 Wegen "B" uns String Ende Zeichen '\0'
 
void setup() {
  Serial.begin(115200);
  byte liste[MAX_LIST_INDEX]={B11111101,B11111001,B11111111,B11111111,B11111111,B11111111,B11111111,B11};
  char buffer[MAX_BUFFER_SIZE];
 
  for (auto element : liste) {
    byteToCharArray(element, buffer, MAX_BUFFER_SIZE);
    Serial.println(buffer);
  }
}
 
void loop() {
  // put your main code here, to run repeatedly:
 
}
 
void byteToCharArray(byte value, char* buf, byte max_buf_size) {
  byte idx=max_buf_size;
  buf[0] = 'B';
  buf[--idx] = '\0';
  for (byte i = 0; i < 8; ++i) {
    buf[--idx] = ((value >> i) & 0x01) ? '1' : '0';
  }
}

Ob es Sinn macht, muss noch geklärt werden.

1 Like