[ create a new paste ] login | about

Link: http://codepad.org/aqzpXVVo    [ raw code | output | fork ]

C, pasted on Oct 18:
#include <stdio.h>
#include <stdlib.h>

void prinbit32(short bit[]);


int main()
{


    short bit[32];
    int i;
int a=2;

    printf("Nhap vao 1 so nguyen: ");
    

    for(i=0;i<=31;i++)
    {
        bit[i]=a%2;
        a=a/2;
    }
    //
    printf("Ma nhi phan dai 32 bit.\n");
    //
    for(i=31;i>=0;i--)
    {
        printf("%d",bit[i]);
    }

    //
    printf("\n================================\n");

    printbit32(bit);

}

void printbit32(short bit[])
{
    int i;
    printf("Ma nhi phan sau khi them dau \" . \"\n ");


    for(i=31;i>=0;i--)
    {
        if((i)%4==0 && (i/4)>=1)
        {
            printf("%d",bit[i]);
            printf(".");
        }
        else
            printf("%d",bit[i]);
    }
}


Output:
1
2
3
4
5
Nhap vao 1 so nguyen: Ma nhi phan dai 32 bit.
00000000000000000000000000000010
================================
Ma nhi phan sau khi them dau " . "
 0000.0000.0000.0000.0000.0000.0000.0010


Create a new paste based on this one


Comments: