2진수

언어/c언어2016. 4. 15. 17:18
#include <stdio.h>
#include <string.h>
#define _SIZE_ 100
#define _TRUE_ 1
typedef int Binary_number;
Binary_number BIN[_SIZE_] = { 0, };// Initillize
void Function_Decial_to_Binary(int*);
int index = 0;
int main(void) {
 int Decimal = 0;
 printf("10진수 입력: ");
 scanf_s("%d", &Decimal);
 Function_Decial_to_Binary(&Decimal);
 return 0;
}
void Function_Decial_to_Binary(int* value) {
 int i;
 int temp_number = 0;
 int temp_remainder = 0;
 while (_TRUE_) {
  temp_remainder = *value % 2;
  BIN[index] = temp_remainder;
  *value = *value / 2;
  index++;
  if (*value == 0) {
   BIN[index] = *value;
   break;
  }
 }
 for (i = index-1; i >=0; i--) {
  printf("%d", BIN[i]);
 }printf("\n");
}

 

'언어 > c언어' 카테고리의 다른 글

포인터  (0) 2016.04.18
버블 정렬  (0) 2016.04.18
회문 판단  (0) 2016.04.15
선택정렬  (0) 2016.04.15
피보나치 수열  (0) 2016.04.14