From 1445e1ef695b8422fcdcadb7f3d3faa4281cd638 Mon Sep 17 00:00:00 2001 From: Aaron Johnon Date: Sun, 1 Sep 2024 21:46:46 -0500 Subject: [PATCH] Added zero padding for large group size numbers --- nsencoder.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nsencoder.go b/nsencoder.go index 692e1a6..48e3c72 100644 --- a/nsencoder.go +++ b/nsencoder.go @@ -127,15 +127,25 @@ func appendNumber(result *[]string, number string, useHex bool, groupSize int) { maxValue = intMaxValue(useHex, maxDigits) } + // Check if the number exceeds the maximum value if num > maxValue { fmt.Fprintf(os.Stderr, "Warning: Number %d is too large for group size %d. Using maximum value %d.\n", num, groupSize, maxValue) num = maxValue } + // Calculate the required length of the number based on the group size + requiredLength := groupSize if useHex { - formatted = fmt.Sprintf("0x%X", num) + requiredLength -= 2 // For "0x" prefix } else { - formatted = fmt.Sprintf("0d%d", num) + requiredLength -= 2 // For "0d" prefix + } + + // Format the number with padding + if useHex { + formatted = fmt.Sprintf("0x%0*X", requiredLength, num) + } else { + formatted = fmt.Sprintf("0d%0*d", requiredLength, num) } *result = append(*result, formatted)