On Sun, Jul 10, 2016 at 5:07 AM, <eavi...@gmail.com> wrote:

> def GetFormattedHex(intNum, lenOfHexString):
> return format(intNum, "0" + str(lenOfHexString) + "x")
>

Where do you get stuck in the translation? It looks pretty straightforward.
Build the table of constants, implement the loop in GetCrc16. Set up a test
case which makes sure you get the same results as the Python version. Then
add a main function for the hex formatting.

The main strategic difference in the above that may come and bite is that
in Python, integers are of arbitrary size, whereas in Go, you will have to
be explicit about the number of bits your integers contain, and also their
signedness. The reference specification[0] may come in handy here.

The secondary thing that may create slight trouble is that you are not
really handling a "string" but rather an array of bytes. Once you get those
types correct, things will usually fall out.

The Go standard packages contain a Crc32 implementation, but it uses a
slighty different way to handle the polynomial. Once your solution works,
it might be of interest to adapt it to be closer to the Golang Crc32
implementation, so your implementation becomes essentially a drop-in
replacement.

[0] https://golang.org/ref/spec#Numeric_types

-- 
J.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to