Reading a PNG’s width and height straight from its bytes
A hex viewer is the tool you reach for when a file will not open, a program says a file is the wrong type, or you want to see what a format really stores. The best way to learn to read one is to take a file you know and find something in it by hand. A PNG image works well, because its layout is short and public.
Open any PNG. The first row starts 89 50 4E 47 0D 0A 1A 0A. Those eight bytes are the PNG signature, and the ASCII column shows .PNG.... because 50 4E 47 are the letters P, N and G. Every PNG starts this way. If a file called photo.png starts with FF D8 FF instead, it is really a JPEG with the wrong name, which is a common reason an upload is rejected.
Next come four bytes, 00 00 00 0D, then 49 48 44 52, which the ASCII column shows as IHDR. The four bytes are the length of the header chunk, 13, and IHDR is its name. The image width starts right after the name, at offset 0x10, and the height at 0x14. Click the byte at 0x10. Say the four bytes there are 00 00 01 2C. With Big-endian selected, UInt32 reads 300: the image is 300 pixels wide. Switch to Little-endian and the same bytes read 738,263,040. Both readings are correct arithmetic. Only one matches the format, and the PNG specification says big-endian, so the width is 300.
Search works the same way. Type IDAT in text mode and press Find to jump to the first block of image data. Press Find next to step to the next one. Search in hex mode for 49 45 4E 44, the IEND chunk name, to find where the image officially ends. Any bytes after IEND are not part of the picture. Some tools hide extra data there, and this is how you would spot it.
The viewer has limits. It shows bytes, not meaning: it does not know any format, so you need the format’s specification to know which offset holds what. It cannot edit or save a file. Text search matches UTF-8, so text stored as UTF-16 needs a hex search. And the number table reads from the selected byte forward, so a value that is not aligned where you clicked will read as something else.