473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Two simple program conversion to Binary

Hi,,
I have two questions as follows:
write a C++ program to convert an unsigned integer number to Binary.
wriet a C++ program to convert a Hexadecimal number to Binary.

I heard that is very easy but I can not write
so, please i want help from us as harry up as you can please.
Oct 15 '07 #1
6 1913
Ganon11
3,652 Expert 2GB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

Then when you are ready post a new question in this thread.

MODERATOR
Oct 15 '07 #2
Thank you very much
I try more than once but i can not write anything so please help me
that becouse i don't have enough knowledge and practice on this material
Oct 16 '07 #3
Ganon11
3,652 Expert 2GB
Regardless, we are not going to do your work for you, whether you are an expert or a beginner. You need to read our Posting Guidelines, especially the points where we clearly tell you how to ask a question (and this thread is not a good example).
Oct 16 '07 #4
JosAH
11,448 Expert 8TB
Hi,,
I have two questions as follows:
write a C++ program to convert an unsigned integer number to Binary.
wriet a C++ program to convert a Hexadecimal number to Binary.

I heard that is very easy but I can not write
so, please i want help from us as harry up as you can please.
I don't know who harry is but think of your own problem a bit: a number is a number
is a number, i.e. if I stick up three fingers it can represent the number three. If
you write down FF is can represent the number 255 (in decimal) for the hexadecimal
representation FF. You want different representations of one and the same number.

Scanf() and printf() format specifiers are quite good at that.

kind regards,

Jos
Oct 16 '07 #5
Hi,,
I have two questions as follows:
write a C++ program to convert an unsigned integer number to Binary.
wriet a C++ program to convert a Hexadecimal number to Binary.

I heard that is very easy but I can not write
so, please i want help from us as harry up as you can please.
Damn, seriously do your own work, and regarding this question, i have the same assignment and i'm from the same university...sheesh, UOB noobie...plus its an assignment ur suppose to do by yourself...
anyway

Here is how far I got on this program, was kinda pain to do but here is how I wrote it...

well its still in development, i'm stuck in the last addition part of the two's complement structure. or did i take the wrong path from the start?


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     unsigned int num=0;
  7.     int size;
  8.     int myarray[20];
  9.     int count;
  10.     for (count = 19; count > 0; count--)
  11.         myarray[count]=0;
  12.  
  13.     cout << "Enter number to convert to binary" << endl;
  14.     cin >> num;
  15.  
  16.     for (size = 0; num > 0; size++)  //Converting to Binary
  17.     {
  18.         myarray[size]=num%2;
  19.         num= num/2;
  20.     }
  21.  
  22.     int i;
  23.     for (i=size-1; i >= 0; i--)            //Printing Binary Number
  24.     {
  25.         cout << myarray[i];
  26.     }
  27.     cout << endl;
  28.  
  29.  
  30.     cout << "Applying Two's Complement" << endl;
  31.  
  32.     for (i=size-1; i >= 0; i--)            //Using Two's Complement.
  33.     {
  34.         if (myarray[i] == 0)
  35.             myarray[i] = 1;
  36.         else
  37.             myarray[i] = 0;
  38.     }
  39.  
  40.     for (i=size-1; i >= 0; i--)            //Printing converted Binary
  41.     {
  42.         cout << myarray[i];
  43.     }
  44.     cout << endl;
  45.  
  46.  
  47.     cout << "Adding One" << endl;
  48.  
  49.  
  50.     if (myarray[0] == 0)
  51.         myarray[0]++;
  52.  
  53.     myarray[size]=1;
  54.     for (i=size; i >= 0; i--)   //Output After Adding 1.
  55.     {
  56.         cout << myarray[i];
  57.     }
  58.     cout << endl;
  59.  
  60.     return 0;
  61. }
Oct 18 '07 #6
its cool fellas, i got the assignment working now, took it the wrong way....
Oct 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Aakash Bordia | last post by:
Hello, Does anybody know what is the documented and known behavior of inserting/updating binary columns using host variables from a client to a server which have different code pages? Will any...
5
by: Yodai | last post by:
Hi all! I have an int that comes with a value like 0x07fa and I have to turn it into a float value of 204.2 decimal to display it.... if I try to divide it by 10 I get bogus numbers. I presume...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
4
by: Russell Warren | last post by:
I've got a case where I want to convert binary blocks of data (various ctypes objects) to base64 strings. The conversion calls in the base64 module expect strings as input, so right now I'm...
2
by: Jan Althaus | last post by:
Mostly for testing reasons I'd like to see if it makes sense to chose the following approach for just-in-time compilation of shaders for a renderer: Seeing as the shaders themsefs consist mostly...
8
by: ftjonsson | last post by:
hello, I was wondering if anyone could tips me on what I am doing wrong when writing the following code: #include <iostream> using namespace std; int main () {
24
by: Fumeur | last post by:
Is the following program standard conform? (reduced as much as possible so it still shows the problem) /* begin */ #include <stdio.h> void xfprintf(FILE *); void xfprintf(FILE *f) {...
6
by: i_robot73 | last post by:
I have a file, containing hex values for dates (MMDDYYYY)<status code><??such as: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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,...
0
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...

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.