Decimal value for top line Hex String in Go

I am converting the decimal (modified) Hex to the fmt.Sprintf function as I am forming a long string with a for loop. But I want the value to be UpperCase and not LowerCase Hex. Where should this happen? In Dec-Hex conversion? Or string modification. Jooin function?

for ....{
b := []string{}
b = append(b, fmt.Sprintf("[%d=%s]", m.K, fmt.Sprintf("%016x", m.V)[2:14]))}

fmt.Fprintf(
            outputFile,
            "%d, 0, %d, %s, 0\n",
        ..,
        ..,
        ..,
        strings.Join(b, " "))

      

+3


source to share


1 answer


Fmt package

import "fmt"

Printing

Verbs:

String and fragment of bytes:

%x    base 16, lower-case, two characters per byte
%X    base 16, upper-case, two characters per byte

      

For example,



fmt.Sprintf("%016X", m.V)[2:14]

      

+3


source







All Articles