Skip to content

Instantly share code, notes, and snippets.

@elenzil
Last active November 11, 2024 07:58
Show Gist options
  • Save elenzil/4a0ac387d4b02cc7752cd237857aecf1 to your computer and use it in GitHub Desktop.
Save elenzil/4a0ac387d4b02cc7752cd237857aecf1 to your computer and use it in GitHub Desktop.
super simple table of hex, decimal, binary and ascii. with source. 0 through 255 and -128 through 127 in decimal, binary, and hex.
/*
0 0x00 0b00000000
1 0x01 0b00000001
2 0x02 0b00000010
3 0x03 0b00000011
4 0x04 0b00000100
5 0x05 0b00000101
6 0x06 0b00000110
7 0x07 0b00000111
8 0x08 0b00001000
9 0x09 0b00001001
10 0x0A 0b00001010
11 0x0B 0b00001011
12 0x0C 0b00001100
13 0x0D 0b00001101
14 0x0E 0b00001110
15 0x0F 0b00001111
16 0x10 0b00010000
17 0x11 0b00010001
18 0x12 0b00010010
19 0x13 0b00010011
20 0x14 0b00010100
21 0x15 0b00010101
22 0x16 0b00010110
23 0x17 0b00010111
24 0x18 0b00011000
25 0x19 0b00011001
26 0x1A 0b00011010
27 0x1B 0b00011011
28 0x1C 0b00011100
29 0x1D 0b00011101
30 0x1E 0b00011110
31 0x1F 0b00011111
32 0x20 0b00100000 ' '
33 0x21 0b00100001 '!'
34 0x22 0b00100010 '"'
35 0x23 0b00100011 '#'
36 0x24 0b00100100 '$'
37 0x25 0b00100101 '%'
38 0x26 0b00100110 '&'
39 0x27 0b00100111 '''
40 0x28 0b00101000 '('
41 0x29 0b00101001 ')'
42 0x2A 0b00101010 '*'
43 0x2B 0b00101011 '+'
44 0x2C 0b00101100 ','
45 0x2D 0b00101101 '-'
46 0x2E 0b00101110 '.'
47 0x2F 0b00101111 '/'
48 0x30 0b00110000 '0'
49 0x31 0b00110001 '1'
50 0x32 0b00110010 '2'
51 0x33 0b00110011 '3'
52 0x34 0b00110100 '4'
53 0x35 0b00110101 '5'
54 0x36 0b00110110 '6'
55 0x37 0b00110111 '7'
56 0x38 0b00111000 '8'
57 0x39 0b00111001 '9'
58 0x3A 0b00111010 ':'
59 0x3B 0b00111011 ';'
60 0x3C 0b00111100 '<'
61 0x3D 0b00111101 '='
62 0x3E 0b00111110 '>'
63 0x3F 0b00111111 '?'
64 0x40 0b01000000 '@'
65 0x41 0b01000001 'A'
66 0x42 0b01000010 'B'
67 0x43 0b01000011 'C'
68 0x44 0b01000100 'D'
69 0x45 0b01000101 'E'
70 0x46 0b01000110 'F'
71 0x47 0b01000111 'G'
72 0x48 0b01001000 'H'
73 0x49 0b01001001 'I'
74 0x4A 0b01001010 'J'
75 0x4B 0b01001011 'K'
76 0x4C 0b01001100 'L'
77 0x4D 0b01001101 'M'
78 0x4E 0b01001110 'N'
79 0x4F 0b01001111 'O'
80 0x50 0b01010000 'P'
81 0x51 0b01010001 'Q'
82 0x52 0b01010010 'R'
83 0x53 0b01010011 'S'
84 0x54 0b01010100 'T'
85 0x55 0b01010101 'U'
86 0x56 0b01010110 'V'
87 0x57 0b01010111 'W'
88 0x58 0b01011000 'X'
89 0x59 0b01011001 'Y'
90 0x5A 0b01011010 'Z'
91 0x5B 0b01011011 '['
92 0x5C 0b01011100 '\'
93 0x5D 0b01011101 ']'
94 0x5E 0b01011110 '^'
95 0x5F 0b01011111 '_'
96 0x60 0b01100000 '`'
97 0x61 0b01100001 'a'
98 0x62 0b01100010 'b'
99 0x63 0b01100011 'c'
100 0x64 0b01100100 'd'
101 0x65 0b01100101 'e'
102 0x66 0b01100110 'f'
103 0x67 0b01100111 'g'
104 0x68 0b01101000 'h'
105 0x69 0b01101001 'i'
106 0x6A 0b01101010 'j'
107 0x6B 0b01101011 'k'
108 0x6C 0b01101100 'l'
109 0x6D 0b01101101 'm'
110 0x6E 0b01101110 'n'
111 0x6F 0b01101111 'o'
112 0x70 0b01110000 'p'
113 0x71 0b01110001 'q'
114 0x72 0b01110010 'r'
115 0x73 0b01110011 's'
116 0x74 0b01110100 't'
117 0x75 0b01110101 'u'
118 0x76 0b01110110 'v'
119 0x77 0b01110111 'w'
120 0x78 0b01111000 'x'
121 0x79 0b01111001 'y'
122 0x7A 0b01111010 'z'
123 0x7B 0b01111011 '{'
124 0x7C 0b01111100 '|'
125 0x7D 0b01111101 '}'
126 0x7E 0b01111110 '~'
127 0x7F 0b01111111
128 0x80 0b10000000
129 0x81 0b10000001
130 0x82 0b10000010
131 0x83 0b10000011
132 0x84 0b10000100
133 0x85 0b10000101
134 0x86 0b10000110
135 0x87 0b10000111
136 0x88 0b10001000
137 0x89 0b10001001
138 0x8A 0b10001010
139 0x8B 0b10001011
140 0x8C 0b10001100
141 0x8D 0b10001101
142 0x8E 0b10001110
143 0x8F 0b10001111
144 0x90 0b10010000
145 0x91 0b10010001
146 0x92 0b10010010
147 0x93 0b10010011
148 0x94 0b10010100
149 0x95 0b10010101
150 0x96 0b10010110
151 0x97 0b10010111
152 0x98 0b10011000
153 0x99 0b10011001
154 0x9A 0b10011010
155 0x9B 0b10011011
156 0x9C 0b10011100
157 0x9D 0b10011101
158 0x9E 0b10011110
159 0x9F 0b10011111
160 0xA0 0b10100000
161 0xA1 0b10100001
162 0xA2 0b10100010
163 0xA3 0b10100011
164 0xA4 0b10100100
165 0xA5 0b10100101
166 0xA6 0b10100110
167 0xA7 0b10100111
168 0xA8 0b10101000
169 0xA9 0b10101001
170 0xAA 0b10101010
171 0xAB 0b10101011
172 0xAC 0b10101100
173 0xAD 0b10101101
174 0xAE 0b10101110
175 0xAF 0b10101111
176 0xB0 0b10110000
177 0xB1 0b10110001
178 0xB2 0b10110010
179 0xB3 0b10110011
180 0xB4 0b10110100
181 0xB5 0b10110101
182 0xB6 0b10110110
183 0xB7 0b10110111
184 0xB8 0b10111000
185 0xB9 0b10111001
186 0xBA 0b10111010
187 0xBB 0b10111011
188 0xBC 0b10111100
189 0xBD 0b10111101
190 0xBE 0b10111110
191 0xBF 0b10111111
192 0xC0 0b11000000
193 0xC1 0b11000001
194 0xC2 0b11000010
195 0xC3 0b11000011
196 0xC4 0b11000100
197 0xC5 0b11000101
198 0xC6 0b11000110
199 0xC7 0b11000111
200 0xC8 0b11001000
201 0xC9 0b11001001
202 0xCA 0b11001010
203 0xCB 0b11001011
204 0xCC 0b11001100
205 0xCD 0b11001101
206 0xCE 0b11001110
207 0xCF 0b11001111
208 0xD0 0b11010000
209 0xD1 0b11010001
210 0xD2 0b11010010
211 0xD3 0b11010011
212 0xD4 0b11010100
213 0xD5 0b11010101
214 0xD6 0b11010110
215 0xD7 0b11010111
216 0xD8 0b11011000
217 0xD9 0b11011001
218 0xDA 0b11011010
219 0xDB 0b11011011
220 0xDC 0b11011100
221 0xDD 0b11011101
222 0xDE 0b11011110
223 0xDF 0b11011111
224 0xE0 0b11100000
225 0xE1 0b11100001
226 0xE2 0b11100010
227 0xE3 0b11100011
228 0xE4 0b11100100
229 0xE5 0b11100101
230 0xE6 0b11100110
231 0xE7 0b11100111
232 0xE8 0b11101000
233 0xE9 0b11101001
234 0xEA 0b11101010
235 0xEB 0b11101011
236 0xEC 0b11101100
237 0xED 0b11101101
238 0xEE 0b11101110
239 0xEF 0b11101111
240 0xF0 0b11110000
241 0xF1 0b11110001
242 0xF2 0b11110010
243 0xF3 0b11110011
244 0xF4 0b11110100
245 0xF5 0b11110101
246 0xF6 0b11110110
247 0xF7 0b11110111
248 0xF8 0b11111000
249 0xF9 0b11111001
250 0xFA 0b11111010
251 0xFB 0b11111011
252 0xFC 0b11111100
253 0xFD 0b11111101
254 0xFE 0b11111110
255 0xFF 0b11111111
0 0x00 0b00000000
1 0x01 0b00000001 -1 0xFF 0b11111111
2 0x02 0b00000010 -2 0xFE 0b11111110
3 0x03 0b00000011 -3 0xFD 0b11111101
4 0x04 0b00000100 -4 0xFC 0b11111100
5 0x05 0b00000101 -5 0xFB 0b11111011
6 0x06 0b00000110 -6 0xFA 0b11111010
7 0x07 0b00000111 -7 0xF9 0b11111001
8 0x08 0b00001000 -8 0xF8 0b11111000
9 0x09 0b00001001 -9 0xF7 0b11110111
10 0x0A 0b00001010 -10 0xF6 0b11110110
11 0x0B 0b00001011 -11 0xF5 0b11110101
12 0x0C 0b00001100 -12 0xF4 0b11110100
13 0x0D 0b00001101 -13 0xF3 0b11110011
14 0x0E 0b00001110 -14 0xF2 0b11110010
15 0x0F 0b00001111 -15 0xF1 0b11110001
16 0x10 0b00010000 -16 0xF0 0b11110000
17 0x11 0b00010001 -17 0xEF 0b11101111
18 0x12 0b00010010 -18 0xEE 0b11101110
19 0x13 0b00010011 -19 0xED 0b11101101
20 0x14 0b00010100 -20 0xEC 0b11101100
21 0x15 0b00010101 -21 0xEB 0b11101011
22 0x16 0b00010110 -22 0xEA 0b11101010
23 0x17 0b00010111 -23 0xE9 0b11101001
24 0x18 0b00011000 -24 0xE8 0b11101000
25 0x19 0b00011001 -25 0xE7 0b11100111
26 0x1A 0b00011010 -26 0xE6 0b11100110
27 0x1B 0b00011011 -27 0xE5 0b11100101
28 0x1C 0b00011100 -28 0xE4 0b11100100
29 0x1D 0b00011101 -29 0xE3 0b11100011
30 0x1E 0b00011110 -30 0xE2 0b11100010
31 0x1F 0b00011111 -31 0xE1 0b11100001
32 0x20 0b00100000 ' ' -32 0xE0 0b11100000
33 0x21 0b00100001 '!' -33 0xDF 0b11011111
34 0x22 0b00100010 '"' -34 0xDE 0b11011110
35 0x23 0b00100011 '#' -35 0xDD 0b11011101
36 0x24 0b00100100 '$' -36 0xDC 0b11011100
37 0x25 0b00100101 '%' -37 0xDB 0b11011011
38 0x26 0b00100110 '&' -38 0xDA 0b11011010
39 0x27 0b00100111 ''' -39 0xD9 0b11011001
40 0x28 0b00101000 '(' -40 0xD8 0b11011000
41 0x29 0b00101001 ')' -41 0xD7 0b11010111
42 0x2A 0b00101010 '*' -42 0xD6 0b11010110
43 0x2B 0b00101011 '+' -43 0xD5 0b11010101
44 0x2C 0b00101100 ',' -44 0xD4 0b11010100
45 0x2D 0b00101101 '-' -45 0xD3 0b11010011
46 0x2E 0b00101110 '.' -46 0xD2 0b11010010
47 0x2F 0b00101111 '/' -47 0xD1 0b11010001
48 0x30 0b00110000 '0' -48 0xD0 0b11010000
49 0x31 0b00110001 '1' -49 0xCF 0b11001111
50 0x32 0b00110010 '2' -50 0xCE 0b11001110
51 0x33 0b00110011 '3' -51 0xCD 0b11001101
52 0x34 0b00110100 '4' -52 0xCC 0b11001100
53 0x35 0b00110101 '5' -53 0xCB 0b11001011
54 0x36 0b00110110 '6' -54 0xCA 0b11001010
55 0x37 0b00110111 '7' -55 0xC9 0b11001001
56 0x38 0b00111000 '8' -56 0xC8 0b11001000
57 0x39 0b00111001 '9' -57 0xC7 0b11000111
58 0x3A 0b00111010 ':' -58 0xC6 0b11000110
59 0x3B 0b00111011 ';' -59 0xC5 0b11000101
60 0x3C 0b00111100 '<' -60 0xC4 0b11000100
61 0x3D 0b00111101 '=' -61 0xC3 0b11000011
62 0x3E 0b00111110 '>' -62 0xC2 0b11000010
63 0x3F 0b00111111 '?' -63 0xC1 0b11000001
64 0x40 0b01000000 '@' -64 0xC0 0b11000000
65 0x41 0b01000001 'A' -65 0xBF 0b10111111
66 0x42 0b01000010 'B' -66 0xBE 0b10111110
67 0x43 0b01000011 'C' -67 0xBD 0b10111101
68 0x44 0b01000100 'D' -68 0xBC 0b10111100
69 0x45 0b01000101 'E' -69 0xBB 0b10111011
70 0x46 0b01000110 'F' -70 0xBA 0b10111010
71 0x47 0b01000111 'G' -71 0xB9 0b10111001
72 0x48 0b01001000 'H' -72 0xB8 0b10111000
73 0x49 0b01001001 'I' -73 0xB7 0b10110111
74 0x4A 0b01001010 'J' -74 0xB6 0b10110110
75 0x4B 0b01001011 'K' -75 0xB5 0b10110101
76 0x4C 0b01001100 'L' -76 0xB4 0b10110100
77 0x4D 0b01001101 'M' -77 0xB3 0b10110011
78 0x4E 0b01001110 'N' -78 0xB2 0b10110010
79 0x4F 0b01001111 'O' -79 0xB1 0b10110001
80 0x50 0b01010000 'P' -80 0xB0 0b10110000
81 0x51 0b01010001 'Q' -81 0xAF 0b10101111
82 0x52 0b01010010 'R' -82 0xAE 0b10101110
83 0x53 0b01010011 'S' -83 0xAD 0b10101101
84 0x54 0b01010100 'T' -84 0xAC 0b10101100
85 0x55 0b01010101 'U' -85 0xAB 0b10101011
86 0x56 0b01010110 'V' -86 0xAA 0b10101010
87 0x57 0b01010111 'W' -87 0xA9 0b10101001
88 0x58 0b01011000 'X' -88 0xA8 0b10101000
89 0x59 0b01011001 'Y' -89 0xA7 0b10100111
90 0x5A 0b01011010 'Z' -90 0xA6 0b10100110
91 0x5B 0b01011011 '[' -91 0xA5 0b10100101
92 0x5C 0b01011100 '\' -92 0xA4 0b10100100
93 0x5D 0b01011101 ']' -93 0xA3 0b10100011
94 0x5E 0b01011110 '^' -94 0xA2 0b10100010
95 0x5F 0b01011111 '_' -95 0xA1 0b10100001
96 0x60 0b01100000 '`' -96 0xA0 0b10100000
97 0x61 0b01100001 'a' -97 0x9F 0b10011111
98 0x62 0b01100010 'b' -98 0x9E 0b10011110
99 0x63 0b01100011 'c' -99 0x9D 0b10011101
100 0x64 0b01100100 'd' -100 0x9C 0b10011100
101 0x65 0b01100101 'e' -101 0x9B 0b10011011
102 0x66 0b01100110 'f' -102 0x9A 0b10011010
103 0x67 0b01100111 'g' -103 0x99 0b10011001
104 0x68 0b01101000 'h' -104 0x98 0b10011000
105 0x69 0b01101001 'i' -105 0x97 0b10010111
106 0x6A 0b01101010 'j' -106 0x96 0b10010110
107 0x6B 0b01101011 'k' -107 0x95 0b10010101
108 0x6C 0b01101100 'l' -108 0x94 0b10010100
109 0x6D 0b01101101 'm' -109 0x93 0b10010011
110 0x6E 0b01101110 'n' -110 0x92 0b10010010
111 0x6F 0b01101111 'o' -111 0x91 0b10010001
112 0x70 0b01110000 'p' -112 0x90 0b10010000
113 0x71 0b01110001 'q' -113 0x8F 0b10001111
114 0x72 0b01110010 'r' -114 0x8E 0b10001110
115 0x73 0b01110011 's' -115 0x8D 0b10001101
116 0x74 0b01110100 't' -116 0x8C 0b10001100
117 0x75 0b01110101 'u' -117 0x8B 0b10001011
118 0x76 0b01110110 'v' -118 0x8A 0b10001010
119 0x77 0b01110111 'w' -119 0x89 0b10001001
120 0x78 0b01111000 'x' -120 0x88 0b10001000
121 0x79 0b01111001 'y' -121 0x87 0b10000111
122 0x7A 0b01111010 'z' -122 0x86 0b10000110
123 0x7B 0b01111011 '{' -123 0x85 0b10000101
124 0x7C 0b01111100 '|' -124 0x84 0b10000100
125 0x7D 0b01111101 '}' -125 0x83 0b10000011
126 0x7E 0b01111110 '~' -126 0x82 0b10000010
127 0x7F 0b01111111 -127 0x81 0b10000001
-128 0x80 0b10000000
*/
// oxe 2018
#include <stdio.h>
#include <ctype.h>
void printBinary(unsigned char value, size_t numDigits) {
for (int n = numDigits - 1; n >= 0; --n) {
int mask = 1 << n;
char c = (value & mask) == 0 ? '0' : '1';
printf("%c", c);
}
}
void printIt(int v) {
unsigned char c = (unsigned char)v;
printf("%4d", v);
printf(" 0x%.2X 0b", c);
printBinary(c, 8);
if (isprint(c)) {
printf(" '%c'", c);
}
else {
printf(" ");
}
}
int main(int argc, const char* argv[]) {
for (int n = 0; n < 256; ++n) {
printIt(n);
printf("\n");
}
printf("\n");
const char* divider = " ";
const char* filler = " ";
printIt(0);
printf("%s", divider);
printf("%s", filler);
printf("\n");
for (int n = 1; n <= 127; ++n) {
printIt(n);
printf("%s", divider);
printIt(-n);
printf("\n");
}
printf("%s", filler);
printf("%s", divider);
printIt(-128);
printf("\n");
}
@Mark-Witucke
Copy link

Thanks! Very cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment