How to convert a number to binary ?

There are four functions available in the AVR library that you might want to use:

char* itoa ( int __val, char * __s, int __radix)

http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga4f6b3dd51c1f8519d5b8fce1dbf7a665

Passing the __radix parameter the value 2 will give you a binary character string.

Cheers, Mikael