본문 바로가기

C언어/프로그래밍

Hex뷰어 소스

#include <stdio.h>

void PrintHexaNAscii(const unsigned char *buffer, int size);

int main()
{
  int a = 0xffffffff;
  PrintHexaNAscii((unsigned char *)&a, 100);
  return 0;
}

void PrintHexaNAscii(const unsigned char *buffer, int size)
{
  int count1;
  int count2;
  const unsigned char *temp=buffer;
  
  printf(" Address   ");        
  for(count1=0; count1<16; count1++)
  {// 메뉴 구분
    printf("%02X ", count1);    
  }                  
  for(count1=0; count1<16; count1++)  
  {                  
    printf("%01X", count1);      
  }                  
  printf("\n");            

  for(count1=0; count1<=size; count1+=16)
  {// 메뉴 주소
    printf("%#X ", buffer);
    for(count2=0; count2<16; count2++)
    {// 번지 주소
      printf("%02X ", *buffer);
      buffer++;
    }
    
    for(count2=0; count2<16; count2++)
    {// 문자 판별65~90 97~122
      printf("%c", ((*temp>=48)&&(*temp<=57)||
              (*temp>=65)&&(*temp<=90)||
              (*temp>=97)&&(*temp<=122)? *temp : '.'));
      temp++;
    }
    printf("\n");
  }
  printf("\n");
  return;
}