need the logc to binary conversion program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • allanarendra_reddy
    New Member
    • Jul 2006
    • 1

    #1

    need the logc to binary conversion program

    hi plz send me the logic for the binary convertio program
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What binary conversion?

    Code:
    int a,b;
    
    b = 4276;
    
    a = ~b;
    here's the logic for a program to invert all the bits of the value 4276.

    Comment

    • Ashish_CPP
      New Member
      • Jul 2006
      • 35

      #3
      Originally posted by allanarendra_re ddy
      hi plz send me the logic for the binary convertio program

      I couldn't understand ur question, if u r asking the logic of printing the binary form of a decimal value then here is the logic.

      unsigned short int i = 2, k = 0;

      for(int j=0;j<16;j++)
      {
      k = i<<j;
      printf("%d",k>> 15);
      }
      getch();

      the above code will print the binary form of the value of i.

      Comment

      • surabhidev
        New Member
        • Sep 2006
        • 1

        #4
        #include<stdio. h>
        #include<conio. h>
        void main()
        {

        int num;
        int i,,j,cnt=0,arr[16];
        int k;
        clrscr();
        printf("\n enter the number:");
        scanf("%d",&num );
        for(i=0;num>0;i ++)
        {
        bin=num%2;
        num=num/2;
        arr[i]=bin;
        cnt++;
        }

        printf('\n the number is :");
        for(j=0;j<=cnt; j++)
        {
        k=(cnt-1)-j;
        printf("%d',arr[k]);
        }



        getch();

        }

        Comment

        Working...