very quick char question

Hi All

Got my first Arduino today and am having a lot of fun making the onboard LED flash (due to a lack of any other electronics at this stage!). I want to convert the binary representation of a char into an array of chars, eg

from:
Char singleLetter = 'h'

to:
Char representLetterInArrayOfBits[] = "1101000"

Does anyone know how this would be done?

Thanks a lot!

Does anyone know how this would be done?

Yes how but not why.

Simply step through all 8 bits in a for loop with a walking one mask and write the appropriate value into your array.

singleLetter = 'h'
mask = 0x01;
for(int i = 0; i<8; i++){
  representLetterInArrayOfBits[i] = 0;
  if((singleLetter & mask) != 0) representLetterInArrayOfBits[i] = 1;
  mask = mask << 1;
}

Thanks for that mike. There's no real reason for wanting to do this other than to learn my way around the language (not done c before) and that it just struck me that I couldn't work out how to do it.

You've given me stuff to look through :slight_smile:

Cheers