Write a code fragment that puts the binary representation of a positive integer n into a String variable s.
Solution. Java has a built-in method Integer. To Binary String(n) for this job, but the point of the exercise is to see how such a method might be implemented. Working from Program 1.3.7, we get the solution
A simpler option is to work from right to left:
Both of these methods are worthy of careful study.
Program 1.3.7
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here