Convert String of binary to their ascii equivalent

I have a string like this one “01100100”

String myString = "01100100";

And a want to convert this string to their ascii equivalent

That in this case is “d”

How can i easily do that?

Could someone post some example code for this conversion...

Thanks!!!

Homework?

Hi,
I don't know if it's the best way to do it, but it works.

void setup() {
  Serial.begin(115200);
  char myByte = 0;
  String myString = "01100100";
  int j = 7;
  for (int i = 0; i < 8; i++)
  {
    if ((myString[i] & 0x0F) == 1)
      bitSet(myByte, j);
    else
      bitClear(myByte, j);
    j--;
  }
  Serial.println(myByte);
}

void loop() {
}
char myString[] = "01100100";
char c = 0x00;

void setup()
{
  Serial.begin(115200);
  
  for (uint8_t x = 0; x < 8; x++)
    c = (c << 1) + myString[x] - '0';

  Serial.println(c);
}

void loop()
{}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.