Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 26 guests and 1 member online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Programmingarrow Any got a solution for this programming challenge ?
EH-Net
May 19, 2013, 06:26:26 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Any got a solution for this programming challenge ?  (Read 2423 times)
0 Members and 1 Guest are viewing this topic.
manoj9372
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« 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...

 
Logged
Dark_Knight
Sr. Member
****
Offline Offline

Posts: 292


View Profile WWW
« Reply #1 on: January 22, 2013, 10:33:16 AM »

Yes..we won't do your homewrok for you Grin Grin Grin Grin

.....just messing with you...
« Last Edit: January 22, 2013, 10:34:54 AM by Dark_Knight » Logged

CEH, OSCP, GPEN, GWAPT, GCIA
http://sector876.blogspot.com
hayabusa
Hero Member
*****
Offline Offline

Posts: 1630



View Profile
« Reply #2 on: January 22, 2013, 10:41:34 AM »

Depends on the language...  It's simple in python...

As of version 2.3

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 Edit: January 22, 2013, 10:45:18 AM by hayabusa » Logged

~ 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'


OSCE, OSCP , GPEN, C|EH
unicityd
Full Member
***
Offline Offline

Posts: 156

Bored IT Manager, Crypto Nerd


View Profile WWW
« Reply #3 on: January 22, 2013, 10:46:05 AM »

Depends on the language...  It's simple in python...

As of version 2.3

bin(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. 
Logged

BS in IT, CISSP, MS in IS Management (in progress)
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #4 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 somehow

if(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" here

for(int i=0; i<number1; i++){

    result = result + number2;
}

return result;

« Last Edit: January 22, 2013, 11:19:39 AM by H1t M0nk3y » Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
hayabusa
Hero Member
*****
Offline Offline

Posts: 1630



View Profile
« Reply #5 on: January 22, 2013, 11:19:00 AM »

I think unicityd's method is likely what they want.

@H1tM0nk3y...  That's why I put my extra 2 bits in, at the end, and noted adding values in the array.  You could simply create an array with all the values in order, then call from the positions, etc.

But really, I think unicityd's method is what they probably wanted.  Wink
Logged

~ 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'


OSCE, OSCP , GPEN, C|EH
manoj9372
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #6 on: January 24, 2013, 02:20:50 AM »

To the first guy
i am not a school kid  Grin
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  Huh

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... Grin



Logged
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #7 on: January 24, 2013, 06:42:49 AM »

Ok, ok, I agree, unicityd has a better solution than me...   Cheesy

I have way too many things on my plate right now to spend cycles on this.

Being a developer, I believe that CPUs and RAM are way cheaper than developer's time (at least, most of the time).

Good luck and please post your solution!  Smiley
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.074 seconds with 23 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.