Overview
In fact, the X-decimal algorithm is similar, but if it is in the form of characters, they are a little different. The use of pointers and arrays is different. Here is a demonstration of the octal format of an array of character types into decimal:
1#include <stdio.h>2#include <string.h>3#include <math.h>4 5#define MAX 106 7Initializes the array to octal.8 void9Init (char *octal) {TenGets (octal); One } A -Convert octal to decimal. - int theOctaltodecimal (char *octal) { -int len = strlen (octal); Actual length. -int sum = 0; Store the results. -int r = 0; Index. + for(int i = len-1; I >= 0; i--) -Sum + = Pow ((float) 8, r++) * (Octal[i]-' 0 '); + returnSum A } at -/* -octal into decimal. -*/ - int -Main (void) { inChar Octal[max]; -Gets (octal); toprintf ("r=%d", Octaltodecimal (octal)); +printf ("\ n"); -}
C-Octal Goto decimal