From 6969cc9d96be0d51eae642134b4f107b97edeb8f Mon Sep 17 00:00:00 2001 From: gutmet Date: Mon, 27 Apr 2020 15:40:27 +0200 Subject: [PATCH] let parse determine the base by prefix (allow octal, byte and hex representation) --- laymanshex.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/laymanshex.go b/laymanshex.go index c5d4db1..3972878 100644 --- a/laymanshex.go +++ b/laymanshex.go @@ -44,7 +44,7 @@ var handlings = map[string]handling{ return strconv.FormatInt(int64(i), 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseInt(s, 10, 8) + i, err := strconv.ParseInt(s, 0, 8) optPanic("conversion of "+s+" to int8 failed", err) binaryWrite(w, bo, int8(i)) }}, @@ -55,7 +55,7 @@ var handlings = map[string]handling{ return strconv.FormatUint(uint64(i), 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseUint(s, 10, 8) + i, err := strconv.ParseUint(s, 0, 8) optPanic("conversion of "+s+" to uint8 failed", err) binaryWrite(w, bo, uint8(i)) }}, @@ -66,7 +66,7 @@ var handlings = map[string]handling{ return strconv.FormatInt(int64(i), 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseInt(s, 10, 16) + i, err := strconv.ParseInt(s, 0, 16) optPanic("conversion of "+s+" to int16 failed", err) binaryWrite(w, bo, int16(i)) }}, @@ -77,7 +77,7 @@ var handlings = map[string]handling{ return strconv.FormatUint(uint64(i), 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseUint(s, 10, 16) + i, err := strconv.ParseUint(s, 0, 16) optPanic("conversion of "+s+" to uint16 failed", err) binaryWrite(w, bo, uint16(i)) }}, @@ -88,7 +88,7 @@ var handlings = map[string]handling{ return strconv.FormatInt(int64(i), 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseInt(s, 10, 32) + i, err := strconv.ParseInt(s, 0, 32) optPanic("conversion of "+s+" to int32 failed", err) binaryWrite(w, bo, int32(i)) }}, @@ -99,7 +99,7 @@ var handlings = map[string]handling{ return strconv.FormatUint(uint64(i), 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseUint(s, 10, 32) + i, err := strconv.ParseUint(s, 0, 32) optPanic("conversion of "+s+" to uint32 failed", err) binaryWrite(w, bo, uint32(i)) }}, @@ -110,7 +110,7 @@ var handlings = map[string]handling{ return strconv.FormatInt(i, 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseInt(s, 10, 64) + i, err := strconv.ParseInt(s, 0, 64) optPanic("conversion of "+s+" to int64 failed", err) binaryWrite(w, bo, i) }}, @@ -121,7 +121,7 @@ var handlings = map[string]handling{ return strconv.FormatUint(i, 10) }, func(w io.Writer, bo binary.ByteOrder, s string) { - i, err := strconv.ParseUint(s, 10, 64) + i, err := strconv.ParseUint(s, 0, 64) optPanic("conversion of "+s+" to uint64 failed", err) binaryWrite(w, bo, i) }},