Well, to convert an integer to a string, the basic itoa
(integer to string) function works somewhat like this:
result = ""
while (number > 0)
{
digit = number % 10
append digit to result
number = number / 10
}
So, there isn't that much of a difference between your first and your second solution. The first solution will take O(n) iterations, where n is the number of digits in the integer. The second solution will have the same complexity, and additionally count the n digits in the string in O(n) time, for a total of O(2n) = O(n) complexity.
Other algorithms are possible. For example, you might take a look at the highest bits that are set, and match those against a table of values.