By passing go type check when performing bitwise operator

99 views
Skip to first unread message

Albert Tedja

unread,
Sep 1, 2019, 2:03:37 PM9/1/19
to golang-nuts
 I am trying to perform some bitwise operators, but Go is not letting me because the mask is an uint and the values are int. Setting the mask to int will break the code since I am shifting bits right and left and prefer the prefix 0 when shifting right, and if I am not mistaken, Go does not have >>>.



Steven Hartland

unread,
Sep 1, 2019, 2:56:13 PM9/1/19
to Albert Tedja, golang-nuts
This has been changed in the upcoming 1.13 release, so you might want to try the latest release candidate.


On 01/09/2019 19:03, Albert Tedja wrote:
 I am trying to perform some bitwise operators, but Go is not letting me because the mask is an uint and the values are int. Setting the mask to int will break the code since I am shifting bits right and left and prefer the prefix 0 when shifting right, and if I am not mistaken, Go does not have >>>.



--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a211253c-eec1-4efb-8f4c-5e94f04e6681%40googlegroups.com.

Michael Jones

unread,
Sep 1, 2019, 7:13:03 PM9/1/19
to Steven Hartland, Albert Tedja, golang-nuts
Int(uint(a) >> uint(b))

Is always ok, costs nothing, not a type safety issue. 

--
Michael T. Jones
michae...@gmail.com

T L

unread,
Sep 2, 2019, 9:40:54 AM9/2/19
to golang-nuts


On Sunday, September 1, 2019 at 2:03:37 PM UTC-4, Albert Tedja wrote:
 I am trying to perform some bitwise operators, but Go is not letting me because the mask is an uint and the values are int. Setting the mask to int will break the code since I am shifting bits right and left and prefer the prefix 0 when shifting right, and if I am not mistaken, Go does not have >>>.



Not like Java, Go supports unsigned integers, so >>> is not essential in Go.
 
Reply all
Reply to author
Forward
0 new messages