Conversor binário
Publicado por Geraldo José Ferreira Chagas Júnior 08/09/2008
[ Hits: 9.894 ]
Homepage: http://prginfo.blogspot.com
Converte um número em binário para decimal, hexadecimal e quando possível, mostra o caractere referente ao valor ASCII.
#include <stdio.h> #include <string.h> #define iifi(c) (((c)=='0') ? (0) : (1)) void intTohex (unsigned long int b, char* hex) { char vet[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; unsigned long int r; r = b % 0x10; hex[7] = vet[r]; b = b >> 0x4; r = b % 0x10; hex[6] = vet[r]; b = b >> 0x4; r = b % 0x10; hex[5] = vet[r]; b = b >> 0x4; r = b % 0x10; hex[4] = vet[r]; b = b >> 0x4; r = b % 0x10; hex[3] = vet[r]; b = b >> 0x4; r = b % 0x10; hex[2] = vet[r]; b = b >> 0x4; r = b % 0x10; hex[1] = vet[r]; b = b >> 0x4; hex[0] = vet[b]; hex[8] = '{FONTE}'; } unsigned long int binToInt (char *str) { return iifi(str[0])*128 + iifi(str[1])*64 + iifi(str[2])*32 + iifi(str[3])*16 + iifi(str[4])*8 + iifi(str[5])*4 + iifi(str[6])*2 + iifi(str[7]); } void arruma (char *dest, char *ori) { int i; int t; t=strlen(ori)-1; for (i=7; i>=0;i--) { if (t>=0) dest[i]=ori[t]; else dest[i]='0'; t--; } dest[8]='{FONTE}'; } char inToChar (unsigned long int val) { if ((val > 32) && (val < 127)) return val; else return '.'; } int main (int argc, char* argv[]) { char temp[9]; unsigned long int valInt; char c; int i; if (argc<2) { printf ("Parametro incorreto.\n"); printf ("Informe apenas os valores em binário\n"); return 1; } for (i=1; i<argc;i++) { arruma(temp, argv[i]); valInt=binToInt(temp); intTohex(valInt,temp); c = inToChar (valInt); printf ("Inteiro=%d Hexa=%s char=%c\n",valInt, temp, c); } }
Jogo do adivinha para descontrair..
Nenhum coment�rio foi encontrado.
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Como gerar um podcast a partir de um livro em PDF
Organizando seus PDF com o Zotero
Erro no realm join [Resolvido]
Um programa para baixar vídeos: Parabolic
Como Definir o Painel Principal em Múltiplos Monitores no Linux Mint
Sempre que vou baixar algum pacote acontece o erro dpkg (7)
como instalo panfrost-dri e o driver panfrost fork , ou panfrost (12)