Page 1 of 1

convert Character string into binary

Posted: Mon Oct 03, 2011 3:24 am
by caltex88
Hi i had a ASCII string, how do i convert it into binary?

I was told to use bit masking to do it.

thanks in advance

Re: convert Character string into binary

Posted: Thu Oct 06, 2011 3:00 am
by buxtronix
For Arduino (you can adapt to your need if pure avr):
Code: Select all
void setup() {
  Serial.begin(9600);
  char *str = "0123";
  for (char *c = str ; *c ; c++)
    for (char b = 7 ; b > -1 ; b--)
      Serial.print((*c >> b) & 0x1 ? "1" : "0");
}

void loop() {
}

Re: convert Character string into binary

Posted: Thu Oct 06, 2011 8:55 pm
by stevech
caltex88 wrote:Hi i had a ASCII string, how do i convert it into binary?

I was told to use bit masking to do it.

thanks in advance
Is the GPS NMEA data question again?