Hexadecimal viewer


Thursday, October 26, 2023 Difficulty: Intermediate

Objective

Create a hexadecimal viewer in Java that shows the contents of a binary file on screen as follows:

  • 16 bytes per row
  • 24 rows on screen
 

The 16 bytes will be displayed first in hexadecimal and then as printable characters. You must also substitute bytes smaller than 32 (unprintable characters) with dots.

Display 24 rows of 16 bytes each time the user presses Enter.

Input

Output

00000000  4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 MZ?.........ÿÿ..
00000010  b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ¸.......@.......
00000020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030  00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 ............?...
00000040  0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68 ..º..´.Í!¸.LÍ!Th
00000050  69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f is program canno
00000060  74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20 t be run in DOS
00000070  6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00 mode....$.......
00000080  50 45 00 00 4c 01 03 00 b2 7c cd cf 00 00 00 00 PE..L...²|ÍÏ....
00000090  00 00 00 00 e0 00 22 00 0b 01 30 00 00 0a 00 00 ....à."...0.....
000000a0  00 08 00 00 00 00 00 00 66 28 00 00 00 20 00 00 ........f(... ..
000000b0  00 40 00 00 00 00 40 00 00 20 00 00 00 02 00 00 .@....@.. ......
000000c0  04 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 ................
000000d0  00 80 00 00 00 02 00 00 00 00 00 00 03 00 60 85 .?............`?
000000e0  00 00 10 00 00 10 00 00 00 00 10 00 00 10 00 00 ................
000000f0  00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ................
00000100  13 28 00 00 4f 00 00 00 00 40 00 00 bc 05 00 00 .(..O....@..¼...
00000110  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000120  00 60 00 00 0c 00 00 00 6c 27 00 00 38 00 00 00 .`......l''..8...
00000130  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000140  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000150  00 00 00 00 00 00 00 00 00 20 00 00 08 00 00 00 ......... ......
00000160  00 00 00 00 00 00 00 00 08 20 00 00 48 00 00 00 ......... ..H...
00000170  00 00 00 00 00 00 00 00 2e 74 65 78 74 00 00 00 .........text...

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Read ID3 v1 tags from MP3 file

Create a Java program that reads ID3 v1 specification tags from an MP3 music file.

2

Read dimensions of BMP image

Create a program in Java to read the dimensions of an image in Windows bitmap format.

3

Encrypt a BMP image

Create a program in Java to encrypt an image in Windows bitmap format.

4

Inverted file

Create a program in Java that inverts all the bytes of a binary file.

5

File copier

Create a Java program that makes copies of both text and binary files.

6

File splitter

Create a Java program that divides text or binary files into parts of 5 Kb each.

7

Hexadecimal viewer

Create a hexadecimal viewer in Java that shows the contents of a binary file on screen as follows.

Binary Files

Practice with exercises in Java to manage binary files. Learn how to create, update, and search binary files in different ways.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play