# EH-Net

## Ethical Hacking Discussions and Related Certifications => Programming => Topic started by: manoj9372 on January 22, 2013, 09:57:35 AM

 Title: Any got a solution for this programming challenge ? Post by: manoj9372 on January 22, 2013, 09:57:35 AM 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.is there a solution possible ?if any one has one please post here...  Title: Re: Any got a solution for this programming challenge ? Post by: Dark_Knight on January 22, 2013, 10:33:16 AM Yes..we won't do your homewrok for you ;D ;D ;D ;D.....just messing with you... Title: Re: Any got a solution for this programming challenge ? Post by: hayabusa on January 22, 2013, 10:41:34 AM Depends on the language...  It's simple in python...As of version 2.3bin(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... Title: Re: Any got a solution for this programming challenge ? Post by: unicityd on January 22, 2013, 10:46:05 AM Quote from: hayabusa on January 22, 2013, 10:41:34 AMDepends on the language...  It's simple in python...As of version 2.3bin(x)I think the point of the challenge is to do it manually.  The easiest way I can think of off-hand is to use a logical AND to test if each bit is set.  Title: Re: Any got a solution for this programming challenge ? Post by: H1t M0nk3y on January 22, 2013, 11:13:10 AM Quote"IT SHOULD NOT USE/INVOKE MULTIPLICATION OR DIVISION OF ANY FORM" inside the computer.The important part is "inside the computer". In python, the bin() function might use multiplications and/or divisions.You can always have a whole bunch of "if" statements. That's not elegant, but it would work for sure:Code:int number;//Set the value of the "number" variable somehowif(number == 0){    return "0000";}else if(number == 1){    return "0001";}else if(number == 2){    return "0010";}...You can also fake multiplications with for loops:Code:int number1;int number2;int result = 0;//Set the value of the "number1" and "number2" herefor(int i=0; i