Skip to content

Commit 9246f8e

Browse files
author
Andrew Marcuse
committed
Hex column for bytecount
1 parent 10af568 commit 9246f8e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bytecount.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
4040
<thead>
4141
<tr>
4242
<th class="text-center">ASCII</th>
43-
<th class="text-center">Byte</th>
43+
<th class="text-center">Decimal</th>
44+
<th class="text-center">Hex</th>
4445
<th class="text-right">Count</th>
4546
<th class="text-right">First</th>
4647
<th class="text-right">Last</th>
@@ -154,6 +155,7 @@ const toAsciiDisplay = (byte: number): string => {
154155
}
155156

156157
const formatOffsetHex = (offset: number): string => `0x${offset.toString(16).toUpperCase().padStart(4, '0')}`
158+
const formatByteHex = (byte: number): string => `0x${byte.toString(16).toUpperCase().padStart(2, '0')}`
157159

158160
const formatOffsetTitle = (offset: number): string => `${offset.toLocaleString()} (decimal)`
159161

@@ -168,7 +170,7 @@ const renderByteCountTable = (byteCounts: Map<number, ByteStats>, totalBytes: nu
168170
.sort(([left], [right]) => left - right)
169171
.map(
170172
([byte, stats]) =>
171-
`<tr><td class="text-center">${toAsciiDisplay(byte)}</td><td class="text-center">${byte}</td><td class="text-right">${formatCount(stats.count)}</td><td class="text-right" title="${formatOffsetTitle(stats.first)}">${formatOffsetHex(stats.first)}</td><td class="text-right" title="${formatOffsetTitle(stats.last)}">${formatOffsetHex(stats.last)}</td></tr>`,
173+
`<tr><td class="text-center">${toAsciiDisplay(byte)}</td><td class="text-center">${byte}</td><td class="text-center">${formatByteHex(byte)}</td><td class="text-right">${formatCount(stats.count)}</td><td class="text-right" title="${formatOffsetTitle(stats.first)}">${formatOffsetHex(stats.first)}</td><td class="text-right" title="${formatOffsetTitle(stats.last)}">${formatOffsetHex(stats.last)}</td></tr>`,
172174
)
173175

174176
resultsBody.innerHTML = rows.join('')

0 commit comments

Comments
 (0)