/* 计算字符串中子串出现的次数。 */ #include<stdio.h> #include<math.h> #include<malloc.h> #include<string.h> #include<stdlib.h> /* 10进制转8进制 */ int convertDecimalToOctal(int num10){ int num8=0,i=1; while(num10!=0){ num8+=(num10%8)*i; i*=10; num10/=8; } return num8; } /* 8进制转10进制 */ int convertOctalToDecimal(int num8){ int num10=0,i=1; while(num8!=0){ num10+=(num8%10)*i; i*=8; num8/=10; } return num10; } /* 2进制转8进制 */ int convertBinarytoOctal(long long num2){ int num8 = 0,num10=0,i=1; while(num2!=0){ num10+=(num2%10)*i; i*=2; num2/=10; } i=1; while(num10!=0){ num8+=(num10%8)*i; i*=10; num10/=8; } return num8; } /* 8进制转2进制 */ int convertOctaltoBinary(int num8){ int num10=0,i=1; long long num2=0; while(num8!=0){ num10+=(num8%10)*i; i*=8; num8/=10; } i=1; while(num10!=0){ num2+=(num10%2)*i; i*=10; num10/=2; } return num2; } main() { printf("%d ",convertDecimalToOctal(78)); printf("%d ",convertOctalToDecimal(116)); printf("%d ",convertBinarytoOctal(101001)); printf("%d ",convertOctaltoBinary(51)); }