1Test::HexDifferences::HUesxeDrumCpo(n3t)ributed Perl DocTuemsetn:t:aHteixoDnifferences::HexDump(3)
2
3
4
6 Test::HexDifferences::HexDump - Format binary to hexadecimal strings
7
9 0.008
10
12 use Test::HexDifferences::HexDump;
13
14 $string = hex_dump(
15 $binary,
16 );
17
18 $string = hex_dump(
19 $binary,
20 {
21 address => $start_address,
22 format => "%a : %4C : %d\n",
23 }
24 );
25
26 Format elements
27 Every format element in the format string is starting with % like
28 sprintf.
29
30 If the given format is shorter defined as needed for the data length
31 the remaining data are displayed in default format. If the given
32 format is longer defined as the data length the output will filled with
33 space and it stops before next repetition.
34
35 Data format
36
37 It is not very clever to use little-endian formats for tests. There is
38 a fallback to bytes if multibyte formats can not displayed.
39
40 %C - unsigned char
41 %S - unsigned 16-bit, endian depends on machine
42 %S< - unsigned 16-bit, little-endian
43 %S> - unsigned 16-bit, big-endian
44 %v - unsigned 16-bit, little-endian
45 %n - unsigned 16-bit, big-endian
46 %L - unsigned 32-bit, endian depends on machine
47 %L< - unsigned 32-bit, little-endian
48 %L> - unsigned 32-bit, big-endian
49 %V - unsigned 32-bit, little-endian
50 %N - unsigned 32-bit, big-endian
51 %Q - unsigned 64-bit, endian depends on machine
52 %Q< - unsigned 64-bit, little-endian
53 %Q> - unsigned 64-bit, big-endian
54
55 "pack" and "unpack" before Perl v5.10 do not allow "<" and ">" to mark
56 the byte order. This is allowed here for all Perl versions.
57
58 "pack" and "unpack" on a 32 bit machine do not allow the "Q" formats.
59 This is allowed here for all machines.
60
61 Address format
62
63 %a - 16 bit address
64 %4a - 16 bit address
65 %8a - 32 bit address
66
67 ASCII format
68
69 It can not display all chars. First it must be a printable ASCII char.
70 It can not be anything of space, q{.}, q{'}, q{"} or q{\}. Otherwise
71 q{.} will be printed.
72
73 %d - display ASCII
74
75 Repetition
76
77 %*x - repetition endless
78 %1x - repetition 1 time
79 %2x - repetition 2 times
80 ...
81
82 Special formats
83
84 %\n - ignore \n
85
86 Default format
87 The default format is:
88
89 "%a : %4C : %d\n"
90
91 or fully written as
92
93 "%a : %4C : %d\n%*x"
94
95 Complex formats
96 The %...x allows to write mixed formats e.g.
97
98 Format:
99 %a : %N %4C : %d\n%1x%
100 %a : %n %2C : %d\n%*x
101 Input:
102 \0x01\0x23\0x45\0x67\0x89\0xAB\0xCD\0xEF
103 \0x01\0x23\0x45\0x67
104 \0x89\0xAB\0xCD\0xEF
105 Output:
106 0000 : 01234567 89 AB CD EF : .#-Eg...
107 0008 : 0123 45 67 : .#-E
108 000C : 89AB CD EF : g...
109
111 Inside of this Distribution is a directory named example. Run this *.t
112 files.
113
115 This is a formatter for binary data.
116
118 subroutine hex_dump
119 $string = hex_dump(
120 $binary,
121 {
122 address => $display_start_address,
123 format => $format_string,
124 }
125 );
126
128 nothing
129
131 nothing
132
134 Hash::Util
135
136 Sub::Exporter
137
139 none
140
142 none
143
145 Test::HexDifferences
146
147 Data::Hexdumper inspired by
148
150 Steffen Winkler
151
153 Copyright (c) 2012 - 2014, Steffen Winkler "<steffenw at cpan.org>".
154 All rights reserved.
155
156 This module is free software; you can redistribute it and/or modify it
157 under the same terms as Perl itself.
158
159
160
161perl v5.30.1 2020-01-30 Test::HexDifferences::HexDump(3)