#Issue with bitwise operations.

9 messages · Page 1 of 1 (latest)

frozen zodiac
#
package main

import (
    "fmt"
)

func main() {
    olds := []int{1 << 0, 1 << 1, 1 << 2, 1 << 3}
    for old := range olds {
        fmt.Printf("%04b\n", old)
    }

    fmt.Printf("%04b\n", 1<<0)
    fmt.Printf("%04b\n", 1<<1)
    fmt.Printf("%04b\n", 1<<2)
    fmt.Printf("%04b\n", 1<<3)
}

When executing "go run main.go", the output was as follows:

0000
0001
0010
0011

0001
0010
0100
1000
please help!

keen fossil
#

Help with...? Maybe with the fact that you're seeing bit representation of indexes instead of actual values?

cedar linden
#

what

#

Ooooh

cinder orchid
#

Lol

#

Just enable inlay hints if your IDE supports them

#

I would annotate the loop like so:

for old /* int */ := range olds {}
#

Nvm, since the value itself is of int type