Untitled
raw download clone
CPP
views 25
,
size 605 b
#include<stdio.h>
int A[32];float x;
int main(void)
{
	while(1){
    
    		scanf("%f",&x);
    		void *ptr = (void*)&x;
    		int out = *((int*)ptr);
    		if(out<0)			//小於零的話就填入1然後把它變成正的
    		{
    		    A[0]=1;out=out*(-1);
    		}
    		else
    		{
    		    A[0]=0;
    		}
    		for(int i=31;i>0;i--)	//從最後一位開始用每次除以二的餘數填入
    		{
    		    A[i]=out%2;
    		    out=out/2;
    		}
    		for(int i=0;i<32;i++)	//印出
    		{
    		    printf("%d",A[i]);
    		}
    		printf("\n");
	}
	return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.