typedef struct
{
unsigned char Asc[4]; //this will hold the ASCII representation of the converted char
unsigned char Bin[13]; //and this will hold an the binary
} CDecodeCharStruct, *pCDecodeCharStruct;
void DecodeChar(unsigned char CharToConvert, pCDecodeCharStruct pDecodeCharStruct)
{
int Loop;
unsigned char AndVal;
//first seperate the digits, no loop for something this simple
pDecodeCharStruct->Asc[0] = CharToConvert / 100; //first get the hundreds
CharToConvert %= 100; //and strip them off our Temp variable
pDecodeCharStruct->Asc[1] = CharToConvert / 10; //now get the tens
CharToConvert %= 10; //and strip them off
pDecodeCharStruct->Asc[2] = CharToConvert; //the ones remain
//now convert this into Binary
for (Loop = 0; Loop < 12; Loop++) //12 binary digits
{
if (!(Loop % 4)) //if we are at the beginning of a new ascii byte
AndVal = 8; //then reset andval
pDecodeCharStruct->Bin[Loop] = !(pDecodeCharStruct->Asc[Loop / 4] & AndVal) ? 0 : 1;
AndVal >>= 1; //ponder this one for a while :)
}
//now convert our Asc into real ASCII numbers
for (Loop = 0; Loop < 3; Loop++)
pDecodeCharStruct->Asc[Loop] += 48;
//and put terminator on Asc so it can be printed
pDecodeCharStruct->Asc[3] = '\0';
}