#include#include#includeunsigned long int puiss(unsigned long int x, int n){ if(n == 0) 1を返します。 if(n == 1) x; unsigned long int x2 = powers(x,n/2); if(n%2 == 0) x2 * x2を返します。 x2 * x2 * x;}int char_to_int(char d){ char str[2]; str[0] = d; str[1] = '\0'; (int)を返す strtol(str, NULL, 10);}unsigned int convertirEnBase10(int binary){ char snum[20]; // String itoa(binary,snum,10); // 何文字ですか? int nc = log10((int)binary)+1; int型10進数= 0; for(int i = nc-1 ; i >= 0; i--) { 10 進数 += char_to_int(snum[i]) * puiss( 2, (nc-1)-i); } 10進数を返します。} int main(){ バイナリint; while(true) { printf("2進数を入力してください "); scanf("%d",&バイナリ); printf("%ld 基数 2 = %ld 基数 10\n",binary, convertInBase10 (バイナリ); } 0を返します。}
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...