So I have the task of creating a program that will take exactly two arguments, the second being an integer. I have to convert that integer to a binary value and then print out the location of the least significant "1" bit. Below is the code I currently have that successfully converts the integer in to binary. I wanted to fill an array with the binary value and then cycle from the last position and decrement a counter until I encountered a "1" and then print out the position of that bit by subtracting the overall length of the array from the current position in the array.
#include <stdio.h>
#include <stdlib.h>
int convert(int);
int main(int argc, char *argv[])
{
int bin;
int n = atoi(argv[2]);
if (argc<2)
{
printf("\nNot Enough Arguments.");
}
if (argc>2)
{
printf("\nToo Many Arguments.");
}
if (argc==2)
{
scanf("%d", &n);
bin = convert(n);
lessbit[] = bin;
}
return 0;
}
int convert(int n)
{
if (n == 0)
{
return 0;
}
else
{
return (n % 2 + 10 * convert(n / 2));
}
}