So we all know it's easy to read a number from lowest place value to highest. A simple algorithm would be like :
while(n):
a=n%10;
n/=10;
but the question is how do you read it oppositely?
for eg : 12312. must result in me getting first 1 then 2 then 3 and so on.
I don't wanna form an array or reverse the number, unless there is a way to reverse the number with constant time-complexity.
Edit : I think the question is extremely vague so I'll try to explain what I need it for.
So i've been working on optimizing my code for an algorithm to convert binary to decimal.
My algorithm is : while(n) c+=(n%2)<<b++ , n/=10;
But then I figured I don't need the variable b, if i could somehow start from the front then an algorithm like c=2*c+n%2 would work.
I don't really wanna use a while loop to reverse a number as I think it would be inefficient than just having an extra variable.
An alternative that I thought of was having a float c then c=c/2+n%2 but the you'll need to know the number of digits of n. Which I could use logarithm for but I don't know that at that point if it is just better to use another variable. At its heart it is a time vs space complexity problem.