#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TAM_MAX 300
void camada_intermediaria(char binario[][9], int decimal[], int tamanho);
int main(void)
{
char binario[TAM_MAX][9];
int decimal[TAM_MAX] = {0};
char frase_binario[TAM_MAX]; //armazenar até 80 sequencias, com tamanho max de 9 (1 caracter pro '\0')
char *delimitador;
int i = 0, tamanho;
//lendo toda a string
scanf("%[^\n]s", frase_binario
);
//criando um splitter pra separar cada cadeia de binários
delimitador
= strtok(frase_binario
, " ");
while(delimitador != NULL)
{
strcpy(binario
[i
++], delimitador
); delimitador
= strtok(NULL
, " "); }
//guardando o tamanho do vetor bidimensional
tamanho = i;
camada_intermediaria(binario, decimal, tamanho);
//camada_intermediaria(binario, tamanho);
return 0;
}
void camada_intermediaria(char binario[][9], int decimal[], int tamanho)
{
int i, j;
int num, pot, dec;
for(i = 0; i < tamanho; i++)
{
dec = 0; // Resetando a variável dec para cada palavra binária
pot = 1; // Inicializa a potência de 2 (equivalente a 2^0)
// Percorrer cada bit da palavra binária de trás para frente
for(j = 7; j >= 0; j--)
{
num = binario[i][j] - '0'; // Converte o caractere para o valor numérico (0 ou 1)
dec += num * pot; // Adiciona a potência de 2 correspondente
pot *= 2; // Multiplica pot por 2 para a próxima potência
}
decimal[i] = dec; // Armazena o valor decimal
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojZGVmaW5lIFRBTV9NQVggMzAwCgp2b2lkIGNhbWFkYV9pbnRlcm1lZGlhcmlhKGNoYXIgYmluYXJpb1tdWzldLCBpbnQgZGVjaW1hbFtdLCBpbnQgdGFtYW5obyk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBjaGFyIGJpbmFyaW9bVEFNX01BWF1bOV07CiAgICBpbnQgZGVjaW1hbFtUQU1fTUFYXSA9IHswfTsKICAgIGNoYXIgZnJhc2VfYmluYXJpb1tUQU1fTUFYXTsgLy9hcm1hemVuYX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