How can I convert an ascii code to binary !
Where is this ASCII coming from? How many digits are there?
A single ASCII digit for the number 4 is the hex value 34. So to store that as a number perform a bitwise logical AND operation with the ASCII and the hex number 0x0F.
That will cope with single digits between 0 and 9.
If the number is in hex format you need a bit more.
This function converts a single char hex digit into a number
unsigned long convertFromHex(int ascii){
if(ascii > 0x39) ascii -= 7; // adjust for hex letters upper or lower case
return(ascii & 0xf);
}
This function uses a global char array called token[] filled with hex ASCII characters and used the above function to convert it into a number
unsigned long tokenInVar(){ // returns the token ID as a number
unsigned long number = 0;
for(int i=0; i<8; i++) number = (number << 4) | convertFromHex(int(token[i]));
return(number);
}