Visualizador hexadecimal
Publicado por Geraldo José Ferreira Chagas Júnior 08/09/2008
[ Hits: 9.077 ]
Homepage: http://prginfo.blogspot.com
Visualiza o conteúdo de um arquivo em escala hexadecimal.
/* viwhexa.c */ #include <stdio.h> void byteToHexa (unsigned char b, char* hex); void intTohex (unsigned long int b, char* hex); int main (int argc, char* argv[]) { FILE *arq; char buf[3]; int contByteLin=0; unsigned long int contLin=1; char pos [9]; int f; if (argc!=2) { printf ("Parametro incorreto.\n"); printf ("Informe apenas o nome do arquivo\n"); return 1; } if (!(arq=fopen(argv[1],"r"))) { printf ("Nao foi possivel abrir o arquivo!\n"); return 1; } printf (" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"); printf (" -----------------------------------------------\n"); printf ("00000000 | "); while (f=fread(buf,1,1,arq)) { if (contByteLin==16) { contByteLin = 0; printf ("\n"); if ((contLin % 0x10) == 0) { printf (" -----------------------------------------------\n"); printf (" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"); printf (" -----------------------------------------------\n"); } intTohex (contLin++, pos); printf ("%s | ",pos); } byteToHexa (buf[0],buf); printf ("%s ",buf); contByteLin ++; } printf ("\n"); close (arq); } void byteToHexa (unsigned char b, char* hex) { char vet[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; int r; int i; r = b % 16; i = (b - r)/16; hex[0] = vet[i]; hex[1] = vet[r]; hex[2] = '{FONTE}'; } 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}'; }
Script para calcular raizes de uma equacao do 2 grau
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Novos apps de produtividade, avanços em IA e distros em ebulição agitam o universo Linux
Desktop Linux ganha novos apps enquanto IA invade o noticiário
Blender 5.0 Beta, Firefox 144 e avanço da IA dominam o dia no mundo Linux
Como mudar o nome de dispositivos Bluetooth via linha de comando
Adicionando o repositório backports no Debian 13 Trixie
Baixar jogos Independentes para Ubuntu [RESOLVIDO] (4)
PIP3 - erro ao instalar módulo do mariadb para o Python (1)
Linux x Plataformas de Trading - um problema (in-)solúvel? (4)