Code block in C language for output human-readable dump with 512 bytes
uint8_t color_dump(void) {
uint16_t i = 0,j = 0,k = 0;
uint8_t side;
printf(“\r\n\033[22;32m\x81 — \x81 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F \x81 XX \x81 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F \x81”);
printf(“\r\n\033[22;32m\x86\x80\x80\x80\x80\x8a\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80”);
for (i = 0; i < 512; i++) {
if (!(i % 16)) {
if (!(i & 16)) {
printf(” \r\n\033[22;36m\x81 %02X \x81”,i / 32);
side = 0;
} else {
printf(“\033[22;35m \x81 %02X \x81”,i / 32);
side = 1;
}
}
if (side = = 0) {
printf(” %02X”, buf[j]);
j++;
} else if (side = = 1) {
if (k % 2) {
printf(“\033[22;35m %02X”, bufe[k]);
} else {
printf(“\033[22;31m %02X”, bufe[k]);
}
k++;
if (!(k % 16)) {
printf(” \x81”);
}
}
}
printf(“\r\n\033[22;32m\x86\x80\x80\x80\x80\x8a\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80”);
printf(“\033[0;37m\r\n\r\n”);
}
Result looks like this:
│ -- │ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F │ XX │ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F │ ├────┼─────────────────────────────────────────────────┼────┼─────────────────────────────────────────────────┤ │ 00 │ 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F │ 00 │ C6 01 69 02 73 03 51 04 FF 05 4A 06 EC 07 29 08 │ │ 01 │ 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F │ 01 │ CD 09 BA 0A AB 0B F2 0C FB 0D E3 0E 46 0F 7C 10 │ │ 02 │ 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F │ 02 │ C2 11 54 12 F8 13 1B 14 E8 15 E7 16 8D 17 76 18 │ │ 03 │ 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F │ 03 │ 5A 19 2E 1A 63 1B 33 1C 9F 1D C9 1E 9A 1F 66 20 │ │ 04 │ 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F │ 04 │ 32 21 0D 22 B7 23 31 24 58 25 A3 26 5A 27 25 28 │ │ 05 │ 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F │ 05 │ 5D 29 05 2A 17 2B 58 2C E9 2D 5E 2E D4 2F AB 30 │ │ 06 │ 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F │ 06 │ B2 31 CD 32 C6 33 9B 34 B4 35 54 36 11 37 0E 38 │ │ 07 │ 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F │ 07 │ 82 39 74 3A 41 3B 21 3C 3D 3D DC 3E 87 3F 70 40 │ │ 08 │ 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F │ 08 │ E9 41 3E 42 A1 43 41 44 E1 45 FC 46 67 47 3E 48 │ │ 09 │ 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F │ 09 │ 01 49 7E 4A 97 4B EA 4C DC 4D 6B 4E 96 4F 8F 50 │ │ 0A │ A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF │ 0A │ 38 51 5C 52 2A 53 EC 54 B0 55 3B 56 FB 57 32 58 │ │ 0B │ B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF │ 0B │ AF 59 3C 5A 54 5B EC 5C 18 5D DB 5E 5C 5F 02 60 │ │ 0C │ C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF │ 0C │ 1A 61 FE 62 43 63 FB 64 FA 65 AA 66 3A 67 FB 68 │ │ 0D │ D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF │ 0D │ 29 69 D1 6A E6 6B 05 6C 3C 6D 7C 6E 94 6F 75 70 │ │ 0E │ E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF │ 0E │ D8 71 BE 72 61 73 89 74 F9 75 5C 76 BB 77 A8 78 │ │ 0F │ F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF │ 0F │ 99 79 0F 7A 95 7B B1 7C EB 7D F1 7E B3 7F 05 80 │ ├────┼─────────────────────────────────────────────────┼────┼─────────────────────────────────────────────────┤
Code that does pretty much the same thing in Python language:
def color_dump(): i = 0 j = 0 k = 0 side = 0 global buf, bufe print ("\r\n\033[1;33m* * 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ** 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F *") for i in range(0, 512): if ( not (i % 16)): if ( not (i & 16)): print ("\033[1;30m%02X " % (i / 32) ), side = 0 else: print ("\033[0;32m%02X" % (i / 32) ), side = 1 if (side == 0): print ("%02X" % buf[j]), j = j+1 elif (side == 1): if (k % 2): print ("\033[1;36m%02X" % bufe[k]), else: print ("\033[1;37m%02X" % bufe[k]), k = k+1 if ( not (k % 16)): print ("\r\n"), print "\033[0;37m" buf = [] bufe = [] for x in range (0,1024): buf.append(0) bufe.append(x) color_dump()
Hope this helps.
Projects like this are born from passion and a desire to share how things work. Education is the foundation of a healthy society - especially important in today's volatile world. xDevs began as a personal project notepad in Kherson, Ukraine back in 2008 and has grown with support of passionate readers just like you. There are no (and never will be) any ads, sponsors or shareholders behind xDevs.com, just a commitment to inspire and help learning. If you are in a position to help others like us, please consider supporting xDevs.com’s home-country Ukraine in its defense of freedom to speak, freedom to live in peace and freedom to choose their way. You can use official site to support Ukraine – United24 or Help99. Every cent counts.
Modified: Dec. 22, 2018, 3:35 a.m.