#include <math.h>
int convertBinaryToOctal(long long binaryNumber);
int main(void){
long long binaryNumber;
printf("Enter a binary number: ");
scanf("%lld", &binaryNumber);
printf("%lld in binary = %d in octal\n", binaryNumber, convertBinaryToOctal(binaryNumber));
return 0;
}
int convertBinaryToOctal(long long binaryNumber){
int octalNumber = 0, decimalNumber = 0, i = 0;
while(binaryNumber != 0){
decimalNumber += (binaryNumber%10) * pow(2,i);
++i;
binaryNumber /= 10;
}
i = 1;
while(decimalNumber != 0){
octalNumber += (decimalNumber %8) * i;
decimalNumber /= 8;
i *= 10;
}
return octalNumber;
}
이진수 입력 : 101001
8 진수로 51
8 진수로 51
댓글 없음:
댓글 쓰기