I pass an array to the function:
char *buffer it stores numbers in decimal notation. It is necessary to translate them into int . The numbers inside - from 0 to 255. The first question is: how to translate each element of a given array into a number in the decimal SI? The second question: there is a function for converting from the 10th SI to the binary one:
void getBin(int num, char *str, int *cnt) { int mask = 0x10 << 1; *(str + 8) = '\0'; while (mask >>= 1) { *str++ = !!(mask & num) + '0'; *(cnt)++; } } Call this function like this:
getBin(number, buf. &counter); where number is the number in decimal notation ( int ); buf - char pointer, in which the result will be written; counter is the int variable that I need to count iterations in a function.
For some reason, after a call to counter 0 is stored, and in the buf not what I need .. Help, please, sort it out.
char *. Now in each memory cell there are stored numbers from 0 to 255. As for the example of the input data, I tried to access the array elements asbuffer[i] - '0', so that they could be converted tointnumbers, but it did not help. Therefore, I think how best to do it. - Setplus