https://play.golang.com/p/TyFQoBR9dQr
package main
import (
“fmt”
)
func main() {
var c int8 = 1 // 00000001
fmt.Println(c << 6) // 01000000 = 64
fmt.Println(c << 7) // 10000000 = -128 ???
}
https://play.golang.com/p/TyFQoBR9dQr
package main
import (
“fmt”
)
func main() {
var c int8 = 1 // 00000001
fmt.Println(c << 6) // 01000000 = 64
fmt.Println(c << 7) // 10000000 = -128 ???
}
Because the int8 is unsigned - so the last bit decides the direction
It looks like you may have already figured it out, but please see Two’s complement - Wikipedia for more information on what’s happening.
if first bit starts with 1 it’s a negative number, otherwise a positive one
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.