How to convert a number to binary ?

If you are talking about a binary string: 3 = "00000011" for example, the following does it:

unsigned char *hex2binstr(unsigned char *str, unsigned char dat) {
  unsigned char mask = 0x80;
  do {
    if (dat & mask) *str='1'; //the bit is 1
    else *str='0'; //otherwise it is 0
    str+=1; //increment the pointer
    mask = mask >> 1; //shift mask
  } while (mask);
  return str;
}

It converts an unsigned char into an 8-char string.

You can then build on top of it routines that convert more complex structures into str.