Problem with hashing to binary


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[26](' ',00100);
  //Serial.println( hashMap.getIndexOf("T"),DEC );
  Serial.println(hashMap.getValueOf('C'), BIN );

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


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.

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.


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.