473,657 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

make a program using C,C++

hi to everybody,i need help for my project....how to make a program
that accept any integer and convert it binary,octal and hexadecimal.pls
help me...thanks

Jan 17 '06 #1
52 4089

"mavic" <ma**********@y ahoo.com> schreef in bericht
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
hi to everybody,i need help for my project....how to make a program
that accept any integer and convert it binary,octal and hexadecimal.pls
help me...thanks


And what should happen to the binary/octal/hexadecimal representation?

Arne
Jan 17 '06 #2
there should be an output of these...

Jan 17 '06 #3
here is a program my friend navjot made to convert decimal system
integer to binary.

u can easily change this program to show octal or hexadecimal or any
other system.

#include<stdio. h>
#include<math.h >
main()
{
int i,x,t,answer=0;
int num[15];

clrscr();

printf("Enter the digits of the binary number \n(pressing Enter
between 2 digits and enter 9 when finished entering) : \n");

for(i=0;i<15;i+ +)
{
scanf("%d",&num[i]);
if( num[i]!=0 && num[i]!=1 )
{break;
}
}

i--;

x=i;

for(t=0;t<=x;t+ +)
{
/* while(i>=0) */
answer+=(pow(2, t)*num[i]);
i--;
}

printf("%d",ans wer);

getch();

}
groups.google.c om/group/all-at-c

Jan 17 '06 #4
this might b of some help :

#include<stdio. h>
main()
{
int num,i=0,q;
int rem[100];
clrscr();

printf("Enter the number : ");
scanf("%d",&num );
q=num;
while(q>0)
{
rem[i]=q%2;
q=q/2;
i++;
}

while( i>=0 )
{
printf("%d",rem[i-1]);
i--;
}
getch();

}
It only converts integer to binary, integer to other systems can b made
similarly.

Anup Bishnoi

Jan 17 '06 #5

"mavic" <ma**********@y ahoo.com> schreef in bericht
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
there should be an output of these...


this should work

#include <stdio.h>

int main()
{
int number = 0, temp = 0, counter = 0;

clrscr();

printf("Give me a number: ");
scanf("%d", &number);
printf("HEXADEC IMAL: %04X\n", number);

printf("Octal: ");
while(counter < (sizeof(int)*8 /3))
{
temp = number << (counter*3);
temp >>= (sizeof(int)*8 -3);
printf("%d", temp);
counter++;
}
printf("\nBinar y: );
counter = 0;
while(counter < (sizeof(int)*8 ))
{
temp = number << (counter);
temp >>= (sizeof(int)*8 -1);
printf("%d", temp);
counter++;
}

return 0;
}

Arne
Jan 17 '06 #6
Ico
Arne Demmers <ar**********@s carlet.be> wrote:

"mavic" <ma**********@y ahoo.com> schreef in bericht
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
there should be an output of these...

[snip homework answer]

Hi Arne,

That's very friendly of you, to do this man's homework; I guess he
really deserves a good grade for that, don't you think so ? His teacher
will be really proud of him, that's for sure. You know, I don't feel
like working today, and I'm just too lazy to learn about the stuff I'm
supposed to be doing, it's all sooooo complicated! If I just tell you
what my job is, can you do it for me ?

Ico

--
:wq
^X^Cy^K^X^C^C^C ^C
Jan 17 '06 #7
here is a program my friend navjot made to convert decimal system
integer to binary form.

u can easily change this program to show octal or hexadecimal or any
other system.

#include<stdio. h>
main()
{
int num,i=0,q;
int rem[100];
clrscr();

printf("Enter the number : ");
scanf("%d",&num );
q=num;
while(q>0)
{
rem[i]=q%2;
q=q/2;
i++;
}

while( i>=0 )
{
printf("%d",rem[i-1]);
i--;
}
getch();

}

Anup Bishnoi
groups.google.c om/group/all-at-c

Jan 17 '06 #8
Ico
Anup Bishnoi <pi***********@ gmail.com> wrote:
this might b of some help : [ snip code ]
It only converts integer to binary, integer to other systems can b made
similarly.


Anup,

Could you please :

- properly quote the messages you are replying to.

- use proper English when posting to this newsgroup. As far as I know,
there are no such words as 'u' and 'b' in English.

- stop making other people's homework. Homework is supposed to give
students a chance to practice the stuff they have learned (or were
supposed to learn); By just giving a way solutions, the man will
graduate his computer course without being able to program properly,
but still he will be assigned to write the fly-by-wire software for
the new Boing plane which you will fly with to your summer holiday
next year. You wouldn't want that plane to crash, would you ?
--
:wq
^X^Cy^K^X^C^C^C ^C
Jan 17 '06 #9
Yes I know, normally I don't do this too, I don't like lazy persons, but it
was somewhat too much basic C for not doing it at all, probaly should have
been better to give some kind of link to a C manual where you can find all
this kind basics..

Anyway next time less luck for guys/women like him...

Arne

"Ico" <us****@zevv.nl > schreef in bericht
news:43******** **************@ dreader32.news. xs4all.nl...
Arne Demmers <ar**********@s carlet.be> wrote:

"mavic" <ma**********@y ahoo.com> schreef in bericht
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
there should be an output of these...

[snip homework answer]

Hi Arne,

That's very friendly of you, to do this man's homework; I guess he
really deserves a good grade for that, don't you think so ? His teacher
will be really proud of him, that's for sure. You know, I don't feel
like working today, and I'm just too lazy to learn about the stuff I'm
supposed to be doing, it's all sooooo complicated! If I just tell you
what my job is, can you do it for me ?

Ico

--
:wq
^X^Cy^K^X^C^C^C ^C

Jan 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3397
by: takashi | last post by:
Hi, I have a question. I am learning about how to use c++ language. I have attempted to make my own programs, using the knowledge that I have, but sometimes when I get stuck on writing a code, it took me a long time to figure out what I should do. For instance, I was writing a program which tells you all the prime numbers that are less than the number you input on the console. It was a very short program, but it took me a while to write...
11
3951
by: bart | last post by:
Hello, I'm so sorry, but i don't understand the concept of the .net environment yet. I made a simple program that retrieves the hostname and ipaddress of the local computer. But when i give thit .exe file to my friend he can't run it because he does not have the framwork 1.1 I thought that the this framework is just a large library of classes wich
17
6429
by: UJ | last post by:
Is there any way for a windows service to start a windows program ? I have a service that will need to restart a windows app if it needs to. TIA - Jeff.
6
4868
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
7
2380
by: Hal Vaughan | last post by:
I have a problem with port forwarding and I have been working on it for over 2 weeks with no luck. I have found C programs that almost work and Java programs that almost work, but nothing that does what I need. I've even tried writing a port forwarder in Java and found problems that nobody seems to have the answer to in forums. I need to make it work essentially the same on both Windows and Linux. There is one program, in C, that...
8
10687
by: Seeker | last post by:
Hello, In using Solaris Pro Compiler to compile Pro*C code. I am getting this error: make: Fatal error in reader: parser_proc_online.mk, line 26: Badly formed macro assignment Based on other posts, this error is not related to C but related more to my lack of understanding. When I look for line 26 in my make file, it does not correlate to a MACRO assignment. Should I count blank or
19
2429
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
48
2102
by: istillshine | last post by:
When I used gprof to see which function consumed most running time, I identified the following one. sz was less than 5000 on average, but foo had been called about 1,000,000 times. I have tried using "register sum = 0.0" and saw some improvement. My question is how to improve foo further to make it faster. double foo(double *a, double *b, int sz) { double sum = 0.0;
42
2045
by: lorlarz | last post by:
Contrary to what one authority in the JavaScript field says: JavaScript does make errors when dealing with just with integers. This authority (Douglas Crockford.) says: "integer arithmetic in floating point is exact" Well, I can prove this is incorrect with this program: http://mynichecomputing.com/digitallearning/yourOwn.htm This a program that uses only integers, yet comes up short in its
82
3672
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from. Let's name the update method as doUpdate and stl::map read methods as getData and copyData. Since stl::map is not thread-safe, we should do synchronization by ourselves. A usable solution is to create a boost::mutex::scoped_lock object in all above...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.