Problem with hashing to binary

Hello.

I’ve been trying to hash letters to binary sequences in accordance with the International Telegraph Alphabet. I wrote the codes down using the hashmap.h library. However, when I open up the serial monitor I only see the binary values in integer format. For example:

Instead of seeing C = 01110, I see the value C=14.

I want to keep it in the binary format, how can I do it? I also tried writing them down as B00100, B11000 etc. but didn’t work. Here is the code:

#include <HashMap.h>

const byte HASH_SIZE = 27; 
HashType<char,byte> hashRawArray[HASH_SIZE]; 
HashMap<char, byte> hashMap = HashMap<char,byte>( hashRawArray , HASH_SIZE ); 

void setup(){
  //setup hashmap
  hashMap[0]('A',11000);
  hashMap[1]('B',10011);
  hashMap[2]('C',01110);
  hashMap[3]('D',10010);
  hashMap[4]('E',10000); 
  hashMap[5]('F',10110);
  hashMap[6]('G',01011);
  hashMap[7]('H',00101);
  hashMap[8]('I',01100);
  hashMap[9]('J',11010);
  hashMap[10]('K',11110);
  hashMap[11]('L',01001);
  hashMap[12]('M',00111);
  hashMap[13]('N',00110);
  hashMap[14]('O',00011);  
  hashMap[15]('P',01101);
  hashMap[16]('Q',11101);
  hashMap[17]('R',01010);
  hashMap[18]('S',10100);
  hashMap[19]('T',00001); 
  hashMap[20]('U',11100);
  hashMap[21]('V',01111);
  hashMap[22]('W',11001);
  hashMap[23]('X',10111);
  hashMap[24]('Y',10101); 
  hashMap[25]('Z',10001);
  hashMap[26](' ',00100);
  Serial.begin(9600);
  //Serial.println( hashMap.getIndexOf("T"),DEC );
  Serial.println(hashMap.getValueOf('C'), BIN );
  
  hashMap.debug();
}

void loop(){/*nothing to loop*/}

Thanks!

Serial.println((int)hashMap.getValueOf('C'), BIN );

Thanks sir, it does work now I see the binary value of C on the serial monitor, however not quite completely.

1110
A - 11000
B - 10011
C - 14
D - 10010
...

This is what i get. At the top I see the value of C, however the first zero is omitted, as C should be 01110.

And afterwards, it still shows C as 14.

hashMap[14]('O',00011);

You do realise that 00011 is an octal number, don't you?

Should I be padding them with zeroes to 8 decimals in total? Sorry, i’m new to these stuff. For example O would be 00000011.

In C, any number starting with a zero is an octal number.
If you want binary, use the “0b” prefix, e.g. 0b1111 == 1510 == 0x0f

Oh, thank you very much for the information :slight_smile: Let me try that way and see if it works.