📄 hex.cpp
字号:
// Created:10-23-98
// By Jeff Connelly
// Hex encoding/decoding, same purpose as UUE/XXE.
// Converts a binary file to a plain text file containing hex digits, two
// per byte. Very inefficent, the file size is doubled! Fast, simple.
#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"
#include <stdio.h>
#define ddig(c) ((c) >= 0x0 && (c) <= 0x9)
#define hdig(c) ((c) >= 0xA && (c) <= 0xF)
#define MASK 0x0F
#define dchr(c) ((c) >= '0' && (c) <= '9') // Decimal character?
#define hchr(c) ((c) >= 'A' && (c) <= 'F') // Hexadecimal letter?
#define CLEAR printf ("\033X");
#define BELL printf ("\007");
// Convert an integer 'c' to a hex string 's'
static char* itohex (register unsigned char c, register char *s)
{
register char c1, c2;
c1 = (c >> 4) & MASK;
c2 = c & MASK;
s[0] = ddig(c1) ? (c1 + '0') : (hdig(c1) ? (c1 - 0xA + 'A') : c1);
s[1] = ddig(c2) ? (c2 + '0') : (hdig(c2) ? (c2 - 0xA + 'A') : c2);
s[2] = 0;
return s;
}
// Converts a hex string to an integer
static char hextoi(register char c1, register char c2)
{
register char i;
i = dchr(c1) ? c1 - '0' : (hchr(c1) ? c1 - 'A' + 0xA : c1);
return (i << 4) + (dchr(c2) ? c2 - '0' : (hchr(c2) ? c2 - 'A' + 0xA : c2));
}
// Encode stream using "hex" scheme
void EXPORT hex_encode()
{
// A byte is encoded in two hex digits
register char a, b, c;
register char* s = "abc";
while (!end_of_data())
{
s[0] = 0;
s[1] = 0;
c = read_byte();
s = itohex(c, s);
a = s[0];
b = s[1];
write_byte(a);
write_byte(b);
}
}
// Decode hex-encoded data
void EXPORT hex_decode()
{
// A byte is repersented in two hex digits
register char a, b;
while (!end_of_data())
{
a = read_byte();
if (end_of_data())
break;
b = read_byte();
write_byte(hextoi(a, b));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -