Two simple program conversion to Binary

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 7anoona
    New Member
    • Oct 2007
    • 5

    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.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    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

    Comment

    • 7anoona
      New Member
      • Oct 2007
      • 5

      #3
      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

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        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).

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by 7anoona
          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

          Comment

          • FunkMan
            New Member
            • Oct 2007
            • 2

            #6
            Originally posted by 7anoona
            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...sh eesh, 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?


            [CODE=cpp]#include <iostream>
            using namespace std;

            int main()
            {
            unsigned int num=0;
            int size;
            int myarray[20];
            int count;
            for (count = 19; count > 0; count--)
            myarray[count]=0;

            cout << "Enter number to convert to binary" << endl;
            cin >> num;

            for (size = 0; num > 0; size++) //Converting to Binary
            {
            myarray[size]=num%2;
            num= num/2;
            }

            int i;
            for (i=size-1; i >= 0; i--) //Printing Binary Number
            {
            cout << myarray[i];
            }
            cout << endl;


            cout << "Applying Two's Complement" << endl;

            for (i=size-1; i >= 0; i--) //Using Two's Complement.
            {
            if (myarray[i] == 0)
            myarray[i] = 1;
            else
            myarray[i] = 0;
            }

            for (i=size-1; i >= 0; i--) //Printing converted Binary
            {
            cout << myarray[i];
            }
            cout << endl;


            cout << "Adding One" << endl;


            if (myarray[0] == 0)
            myarray[0]++;

            myarray[size]=1;
            for (i=size; i >= 0; i--) //Output After Adding 1.
            {
            cout << myarray[i];
            }
            cout << endl;

            return 0;
            }[/CODE]
            Last edited by Ganon11; Oct 18 '07, 01:08 PM. Reason: Please use the [CODE] tags provided.

            Comment

            • FunkMan
              New Member
              • Oct 2007
              • 2

              #7
              its cool fellas, i got the assignment working now, took it the wrong way....

              Comment

              Working...