Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

1a. Write a recursive algorithm that converts a decimal number D in base 10 (between 0 and 1023) to a binary number B in base 2. A base 10 number uses the ten digits 0, 1, …, 9, while a base 2 number uses only the two digits 0 and 1. For example: D: 29 B: 11101 (since 1*24 + 1*23 + 1*2 2 + 0*21 + 1*20 = 29) D: 999 B: 1111100111 1b.) Trace your algorithm for D = 13

OpenStudy (rsmith6559):

Here, this works for any base up to 36 #!/usr/bin/python characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" def mkDigit( number, base ): if( number == 0 ): return "" index = number % base number = number // base return mkDigit( number, base ) + characters[ index ] if( __name__ == "__main__" ): number = int( raw_input( "Enter the number: " ) ) base = 0 while( base < 2 or base >= len( characters ) ): base = int( raw_input( "Enter the base ( 2 - " + str( len( characters ) -1 ) + " ): " ) ) print mkDigit( number, base )

OpenStudy (anonymous):

thanks, can this be implemented in Java? or is it C?

OpenStudy (anonymous):

It's python. But it could be implemented in any programming language.

OpenStudy (anonymous):

thanks!

OpenStudy (anonymous):

Can some one also help me with the 2nd Question as well? i have done 3 and 4 this is the last one i have to do. Its large so its attached as a Word document. if you could send it back as an attachment that would be great.

OpenStudy (anonymous):

What have you tried so far? Where are you stuck?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!