Created
July 29, 2019 22:45
-
-
Save parzibyte/9e51db4310c3baff551059f7da7f9200 to your computer and use it in GitHub Desktop.
Octal a decimal en C - https://parzibyte.me/blog/2018/11/20/octal-decimal-c/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Algoritmo que convierte un número octal | |
a uno decimal en C | |
@author parzibyte | |
Visita: parzibyte.me1 | |
*/ | |
unsigned long long octalADecimal(char *cadenaOctal, int longitud) { | |
unsigned long long decimal = 0; | |
int potencia = 0; | |
for (int i = longitud - 1; i >= 0; i--) { | |
int valorActual = cadenaOctal[i] - '0'; | |
// Elevar 8 a la potencia que se va incrementando, y multiplicarla por el | |
// valor | |
unsigned long long elevado = pow(BASE, potencia) * valorActual; | |
// Agregar al número | |
decimal += elevado; | |
// Avanzar en la potencia | |
potencia++; | |
} | |
return decimal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment