Convert const char to binary

I am on a journey of discovery. Having designed the hardware for a hybrid AVR/Z80 Experimenters board, I now need to get it to work. The main challenge I have is the more advanced AVR programming than I'm used to.

I am using an ATMEGA1284P to supervise a Z80. I'm currently trying to work out how to convert a hex character held in a character array into individual bits that will be presented across my projects databus and in turn, be moved to SRAM. The details of the project can be seen here: https://hackaday.io/project/7354-zaviour-board-avrz80-hybrid

I'm not sure if what I require can be done directly from the array or if each character (byte) would need an intermediate conversion.

All help gratefully appreciated.
Would this help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bitset>
...

//declare variable
char a = -58;
short c = -315;

//display 8 bit
std::bitset<8> x(a);
std::cout << x;

//display 16 bit
std::bitset<16> y(c);
std::cout << y;
Each Hex character is in base 16 and can be represented with 4 bits
Cheers guys. I can't get to a PC until tomorrow but I'll explore your ideas then.
Lbkulinski, Hi. I tried your code and the Arduino IDE balked at the #include <bitset>. Thinking it may be built in to the IDE, I commented it out but got other errors. I think that possibly, I've asked my question in the wrong place. I'll pop over to the Arduino forums. I do appreciate your help though. And Smac89, I've noted your info, thanks.
Topic archived. No new replies allowed.