黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

C 語言實(shí)例 – 八進(jìn)制與二進(jìn)制相互轉(zhuǎn)換

C 語言實(shí)例 - 八進(jìn)制與二進(jìn)制相互轉(zhuǎn)換

C 語言實(shí)例 C 語言實(shí)例

八進(jìn)制與二進(jìn)制相互轉(zhuǎn)換。

實(shí)例 - 二進(jìn)制轉(zhuǎn)換為八進(jìn)制

#include <stdio.h> #include <math.h> int convertBinarytoOctal(long long binaryNumber); int main() { long long binaryNumber; printf("輸入一個(gè)二進(jìn)制數(shù): "); scanf("%lld", &binaryNumber); printf("二進(jìn)制數(shù) %lld 轉(zhuǎn)換為八進(jìn)制為 %d", 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; }

輸出結(jié)果為:

輸入一個(gè)二進(jìn)制數(shù): 101001
二進(jìn)制數(shù) 101001 轉(zhuǎn)換為八進(jìn)制為 51

實(shí)例 - 八進(jìn)制轉(zhuǎn)換為二進(jìn)制

#include <stdio.h> #include <math.h> long long convertOctalToBinary(int octalNumber); int main() { int octalNumber; printf("輸入一個(gè)八進(jìn)制數(shù): "); scanf("%d", &octalNumber); printf("八進(jìn)制數(shù) %d 轉(zhuǎn)二進(jìn)制為 %lld", octalNumber, convertOctalToBinary(octalNumber)); return 0; } long long convertOctalToBinary(int octalNumber) { int decimalNumber = 0, i = 0; long long binaryNumber = 0; while(octalNumber != 0) { decimalNumber += (octalNumber%10) * pow(8,i); ++i; octalNumber/=10; } i = 1; while (decimalNumber != 0) { binaryNumber += (decimalNumber % 2) * i; decimalNumber /= 2; i *= 10; } return binaryNumber; }

輸出結(jié)果為:

輸入一個(gè)八進(jìn)制數(shù): 51
八進(jìn)制數(shù) 51 轉(zhuǎn)二進(jìn)制為 101001

C 語言實(shí)例 C 語言實(shí)例

相關(guān)文章