decimal is the number entered by the user.
binary [] is the char array and count is... you know how many times the for loop will turn. So my question is, how do i know the length of the number ? does anyone know any function that shows the integer length ? because its impossible to know what count is equal to. like 100 is 3.
Thanks in advance
which can be calculated by int(log(decimal)/log(2)) + 1
There is some danger of under-representing exact powers of 2. e.g. log_base2(4) = 2 but possibly some calculation error would lead to 1.9999999999999999 which would then be rounded down to 1
The simplest option to be safe is to add an extra char just in case. i.e. use
int(log(decimal)/log(2)) + 2 as the space to reserve