# Decimal To Binary

• (3 Pages)
• 1
• 2
• 3

## 39 Replies - 22904 Views - Last Post: 07 December 2008 - 08:38 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=9675&amp;s=a61cfc4006daed6527383edf6d225918&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

# Decimal To Binary

Posted 26 October 2004 - 11:11 AM

So... my bf is working on a program in VB on converting decimal numbers to binary numbers... i vaguely remember doing it in C++ LONG time ago... i was just wondering...if someone could refresh my memory of how to do it... you don't have to give code.. just explanation... because i remember doing it... but i don't use c++ any more so my coding is rusty....
Thx
Is This A Good Question/Topic? 0

## Replies To: Decimal To Binary

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: Decimal To Binary

Posted 26 October 2004 - 12:11 PM

While there are several tools to convert decimal numbers to binary, this page shows the two most common ways to do it. It's easy to translate the method into code.

### #3 skyhawk133

Reputation: 1953
• Posts: 20,380
• Joined: 17-March 01

## Re: Decimal To Binary

Posted 26 October 2004 - 12:13 PM

Whoa, what's up Amy!

### #4 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

## Re: Decimal To Binary

Posted 26 October 2004 - 03:08 PM

thx.... i have an idea of what to do... we will see... cuz there's another part to it.. that i absolutely don't understand... but i'll do more research on it...

### #5 skyhawk133

Reputation: 1953
• Posts: 20,380
• Joined: 17-March 01

## Re: Decimal To Binary

Posted 26 October 2004 - 03:32 PM

Hi Amy, nice to see you too, I've been great... thanks for asking, oh, what I've been up to!? Eh, you know, same ole same ole. You?!

### #6 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

## Re: Decimal To Binary

Posted 26 October 2004 - 03:38 PM

HI chris.. i am sorry that you felt ignored.. but i was trying to keep a technical post TECHNICAL and not social.... and how are you.. how have you been and how's business....... *thinking to self.. god... he is an attention monger*

### #7 skyhawk133

Reputation: 1953
• Posts: 20,380
• Joined: 17-March 01

## Re: Decimal To Binary

Posted 26 October 2004 - 03:40 PM

I've been good, check out my latest project

http://www.mg1hosting.com

### #8 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

## Re: Decimal To Binary

Posted 26 October 2004 - 03:46 PM

### #9 Nova Dragoon

• The Innocent Shall Suffer, Big Time

Reputation: 36
• Posts: 6,169
• Joined: 16-August 01

## Re: Decimal To Binary

Posted 26 October 2004 - 06:24 PM

skyhawk133, on Oct 26 2004, 04:40 PM, said:

I've been good, check out my latest project

http://www.mg1hosting.com

yeah chris, that pretty much sums you up

http://www.mg1hosting.com

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: Decimal To Binary

Posted 26 October 2004 - 07:05 PM

I'm not sure what you mean by more to it, but I'll try to help if you can explain it to me. The division method is uusally the easiest to represent in code. You can use the algorithm outlined here
I may be misunderstanding your question, however. If so, my apologies.

This post has been edited by Amadeus: 26 October 2004 - 07:06 PM

### #11 skyhawk133

Reputation: 1953
• Posts: 20,380
• Joined: 17-March 01

## Re: Decimal To Binary

Posted 26 October 2004 - 09:32 PM

Nova Dragoon, on Oct 26 2004, 07:24 PM, said:

skyhawk133, on Oct 26 2004, 04:40 PM, said:

I've been good, check out my latest project

http://www.mg1hosting.com

yeah chris, that pretty much sums you up

http://www.mg1hosting.com

Inside joke... you wouldn't understand.

### #12 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 187
• Posts: 4,673
• Joined: 26-November 04

## Re: Decimal To Binary

Posted 30 December 2004 - 02:33 AM

Wierd....I thought every1 out here knew how to convert Decimal to Binary....well since noone gave the method anyhow....here's my code...simple as it is....still if you have any problems let me know.
There are many ways of doing this...out of which I'll explain two. Here's the First one...in which you dont even have to bother about how the conversion is done:
```#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

void main()
{
int i=23;
char c[23];
clrscr();
cout<<"Enter any Number in Decimal to be converted in Binary\n";
cin>>i;
cout<<itoa(i,c,2);
getch();
}

```

Here's the Second Method:
```#include <iostream.h>
#include <conio.h>

void main()
{
int i, ch;
cout<<"Enter an integer: ";
cin>>ch;
for(i=0x80;i;i=i>>1)
cout<<((ch&i)?'1':'0');

getch();
/*
these 2 lines are equivalent to:
i=0x80; //10000000 in binary
while (i!=0)
{
if (ch&i)
cout<<'1';
else
cout<<'0';
i>>1;
}
*/

}

```

Hope It helps you all.

### #13 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 187
• Posts: 4,673
• Joined: 26-November 04

## Re: Decimal To Binary

Posted 30 December 2004 - 02:38 AM

Man....real bad formatting style...the CODE tags really ruin everything up....I'm attaching the 2 methods of converting Decimal to Binary as 2 Source Code Files.

Great...I gotta reply again to add both the files...I think an improvement to this forums would be to attach multiple files. Or do they want us to attach ZIP Archives instead?
In any case....i'll reply once more...
This is the First Method

### #14 born2c0de

• printf("I'm a %XR",195936478);

Reputation: 187
• Posts: 4,673
• Joined: 26-November 04

## Re: Decimal To Binary

Posted 30 December 2004 - 02:44 AM

Here's Method Number 2 Attached

#### Attached File(s)

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

## Re: Decimal To Binary

Posted 30 December 2004 - 06:23 AM

Excellent methods. I'm not sure I'd agree that everyone would know how to do the conversion, there are several groups here, many of which deal with graphics and subjects other that programming.