how to convert high decimal values into binary code and show them with sprintf ??

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello guys,

   

I need to convert some hugh values (~120000) into binary code. Unfortunately this only works if my value is 1023 or less.

   

Does anyone have an idea? Is something wrong with the conversion or just with the sprintf? I tried to change the argument %... of sprintf but no success.

   

long   num, decimal_num, remaind, base =1, binary =0; 

   

  num= 1023;
    decimal_num = num;
    while (num>0)
    {
        remaind = num %2;
        binary = binary + remaind * base;
        num = num/2;
        base=base*10;
    }
    sprintf(TransmitBuffer, "real_comb_binary: %ld \n", binary);
    UART_1_PutString(TransmitBuffer);

   

Thanks in advance,

   

Alex

0 Likes
7 Replies