hi guys,here is challenge i got from my friend,i just want to know there is a solution available for this task,

when i enter a number it should display it's equivalent binary number like for 2 = 0010 3=0011,but the important restriction is "IT SHOULD NOT USE/INVOKE MULTIPLICATION OR DIVISION OF ANY FORM" inside the computer.

bin(x)Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

You'd just need to strip off the first two characters of the return, such as:

Code:

val=bin(8);newval=val.replace("0b", "");print newval;

Now, we'll assume that the bin() uses multiplication / division inside of itself, so if you really wanted to do this, without ANY, you'd likely need to create an array of values, during runtime, where you GIVE it the values, and parse the array to return them. That's if he's TRULY not allowing the use of the builtin functions of python to do the work...

Last edited by hayabusa on Tue Jan 22, 2013 11:45 am, edited 1 time in total.

~ hayabusa ~

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'

To the first guy i am not a school kid we need this logic to show that in REAL LIFE that program can produce much faster results than the hardware,that is the main task of this program and TBH i am not a programmer

And guys when i asked for solutions for this program from other programmers they urged me to use some kind of bit shifting to do this,and it seems "unicityd" points were right...