7 Replies Latest reply on Nov 4, 2015 5:07 AM by alexander.bromm

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

    alexander.bromm

      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