FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/strings/Hex.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
strings
/
Hex.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (43 loc) · 1.36 KB
Breadcrumbs
OnJava8-Examples
/
strings
/
Hex.java
Copy path
File metadata and controls
44 lines (43 loc) · 1.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// strings/Hex.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.Hex}
package
onjava
;
import
java
.
io
.*;
import
java
.
nio
.
file
.*;
public
class
Hex
{
public
static
String
format
(
byte
[]
data
) {
StringBuilder
result
=
new
StringBuilder
();
int
n
=
0
;
for
(
byte
b
:
data
) {
if
(
n
%
16
==
0
)
result
.
append
(
String
.
format
(
"%05X: "
,
n
));
result
.
append
(
String
.
format
(
"%02X "
,
b
));
n
++;
if
(
n
%
16
==
0
)
result
.
append
(
"
\n
"
);
}
result
.
append
(
"
\n
"
);
return
result
.
toString
();
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
args
.
length
==
0
)
// Test by displaying this class file:
System
.
out
.
println
(
format
(
Files
.
readAllBytes
(
Paths
.
get
(
"build/classes/java/main/onjava/Hex.class"
))));
else
System
.
out
.
println
(
format
(
Files
.
readAllBytes
(
Paths
.
get
(
args
[
0
]))));
}
}
/* Output: (First 6 Lines)
00000: CA FE BA BE 00 00 00 34 00 61 0A 00 05 00 31 07
00010: 00 32 0A 00 02 00 31 08 00 33 07 00 34 0A 00 35
00020: 00 36 0A 00 0F 00 37 0A 00 02 00 38 08 00 39 0A
00030: 00 3A 00 3B 08 00 3C 0A 00 02 00 3D 09 00 3E 00
00040: 3F 08 00 40 07 00 41 0A 00 42 00 43 0A 00 44 00
00050: 45 0A 00 14 00 46 0A 00 47 00 48 07 00 49 01 00
...
*/
Back
|
FazBrowse Home
|
New Git URL