Converting a short decimal into binary using a short not libary

This is a discussion on Converting a short decimal into binary using a short not libary within the C Programming forums, part of the General Programming Boards category; Converting a short decimal into binary using a short, no libary. I just want help, it doesnt do anthing past ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    8

    Exclamation Converting a short decimal into binary using a short not libary

    Converting a short decimal into binary using a short, no libary.
    I just want help, it doesnt do anthing past the printf statment.

    I dont want anyone to write the whole thing for me.

    As i said im just lost and dont know what to do
    Thank you so very much
    still new to C programming.

    Code:
     #include
    Code:
    <stdio.h>
    short inputnumber ; // the number taken from the user 
    int temp;
    int j = 0; //counts the array loctions when printing
    int count;// equals the number you entered
    int i = 0;// counts the array loctions when it enters binary number
    int binout[16] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//
    int _tmain(int argc, _TCHAR* argv[])
    {
    //Asked user for their number
    printf("Please enter a number that is 16 bits\n");
    
    //scans the user number
    scanf_s("%i",&inputnumber);
    count = inputnumber;//
    
    // useing mod to check if there is a remainer adding 1 if 0 or 1 if its a 1 doing 2's comp
    
    while ( count =! 0) 
    
    if (count % 2 == 0 )
    {binout[i] = 1;
    count = count / 2;
    ++i;}//
    else (binout[i] = 0); {count = count / 2; ++i;} //changing the first bit to the oppisite 2's comp if (binout[0] = 0) {binout[0] = 1;} else (binout[0] = 0); // printing you're number in binary while (j < 16, ++j ) {printf("You're number in 2's comp binary %i", &binout[j]);} return 0;}

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Code:
    printf("You're number in 2's comp binary %i", &binout[j]);
    %i prints an integer, but &binout[j] is an address.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    Code:
    else (binout[i] = 0);
    {count = count / 2;
    ++i;}
    what gets executed as the else?

    Code:
    count =! 0
    what does this do?

    edit:most microprocessors already represent their numbers internally as 2s-complement. since you are on Windows, the value is already in that format. unless i don't understand what you want to print, you don't need to swap that bit.
    Last edited by dmh2000; 09-26-2012 at 04:35 PM. Reason: more info

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    How would you print the address? I want to put the binary represetation of an int into binout[] and print it out.

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    You are right i'm trying to switch it to 2s complement. I understand windows does this for me but the program just need to show that i know how to do this.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,301
    If you need more help, please post the updated code after having fixed the things that were hinted at above.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting decimal to binary
    By BrandNewDeipz in forum C Programming
    Replies: 4
    Last Post: 03-03-2012, 08:34 AM
  2. How come short + int = int but short + uint = long?
    By y99q in forum C# Programming
    Replies: 2
    Last Post: 10-29-2011, 11:16 AM
  3. shortening this short code? : binary to int casting
    By OldGit in forum C Programming
    Replies: 21
    Last Post: 02-25-2009, 11:10 AM
  4. Replies: 2
    Last Post: 04-21-2008, 07:43 PM
  5. Replies: 7
    Last Post: 02-08-2008, 05:31 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21