Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Please, Need Help To Convert Decimal To Binary Numbers
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Taruen




PostPosted: Wed May 31, 2006 9:32 pm   Post subject: Please, Need Help To Convert Decimal To Binary Numbers

Hey... i'm lookin for some help in creating a small program that converts decimal or numbers... into binary numbers... any help please.?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed May 31, 2006 10:05 pm   Post subject: (No subject)

000 = 0 = 0
001 = 2^0 = 1
010 = 2^1 = 2
011 = 2^1 + 2^0 = 3
100 = 2^2 = 4
101 = 2^2 + 2^0 = 5
111 = 2^2 + 2^1 + 2^0 = 6

notice any patterns?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Taruen




PostPosted: Wed May 31, 2006 10:08 pm   Post subject: (No subject)

lol yeah i sorta get it.... but i just need help makin a program... like when i click a command button after entering a number in a text box... i want it to show on a label.. the binary number of itl... how would i program that?
NikG




PostPosted: Thu Jun 01, 2006 12:49 am   Post subject: (No subject)

We can't give the code to you, especially considering this is a common assignment in schools from what I remember.

Tony gave you a clue. All you gotta do is find a way to go in the opposite direction that Tony showed.
Brightguy




PostPosted: Thu Jun 01, 2006 11:35 am   Post subject: Re: Please, Need Help To Convert Decimal To Binary Numbers

As a hint, you'll want to use Mod and integer division (the \ operator).

Start by finding the least significant bit (the right-most) and then the next least significant, etc. Then get it in a loop so you find one bit each time through the loop.
NikG




PostPosted: Thu Jun 01, 2006 11:37 am   Post subject: (No subject)

I believe I've also managed to successfully do this using string manipulation and a for loop (i.e. no Math operators).
Tony




PostPosted: Thu Jun 01, 2006 11:47 am   Post subject: Re: Please, Need Help To Convert Decimal To Binary Numbers

Brightguy wrote:
Start by finding the least significant bit (the right-most) and then the next least significant, etc.

Shouldn't it be the other way around, with the left most?

5 mod 2^2 < 5 -- you've got your first bit (of 3)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Brightguy




PostPosted: Thu Jun 01, 2006 4:23 pm   Post subject: Re: Please, Need Help To Convert Decimal To Binary Numbers

Right now I don't see any advantages starting from the most-significant. But if you wanted to do it like that, why even use Mod? Just directly compare to powers of 2.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jun 01, 2006 4:40 pm   Post subject: (No subject)

well yeah, pretty much.

How are you even expecting on finding the least significant bit?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Brightguy




PostPosted: Thu Jun 01, 2006 6:54 pm   Post subject: Re: Please, Need Help To Convert Decimal To Binary Numbers

Tony wrote:
How are you even expecting on finding the least significant bit?

That's what Mod is for. Even numbers have a 0 for the lsb, odd numbers have a 1. (I'm guessing you already knew that, though...)

I would say there's often a slight advantage doing it from least-to-most significance, since you don't have to start by finding the starting bit.
Tony




PostPosted: Thu Jun 01, 2006 7:05 pm   Post subject: (No subject)

well you'd still need to find the starting bit, otherwise you wouldn't know where to stop Wink

you're right, it could be approached from ether direction. Though when starting with lsb, you'd need to bitshift after determining each bit. As oppose to subtracting 2^n from the decimal value. Main difference being the confusion to the student requiring help with conversions Razz
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: