On Tuesday, 7 March 2017 19:02:59 UTC-5, Eric Brown wrote: > > memoryBlock := make([]byte, 4) > > binary.LittleEndian.PutUint32(memoryBlock, 12345678) > > > > memoryBlock[2] = 256 - (187 - memoryBlock[2]) ' results in error: > constant 256 overflows byte > memoryBlock[2] = 255 - (187 - memoryBlock[2]) + 1 ' results in no errors > > > Why is this, and what would be your suggested method of handling this? > I don't like having to do the later as it just looks sloppy. > > Byte operations work modulo 256, so adding 256 does nothing.
Using that, you can simplify your expression to this: memoryBlock[2] -= 187 https://play.golang.org/p/5ljs4wIeq9 -- Paul Hankin -- 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.