I came across this in Golang and the result is not so obvious to me, here is the code:
package main
import "fmt"
func main() {
a := 'a'
b := a | 'b'
fmt.Println(b)
}
Does it print a
? Does it print b
?
No, the result in the console is 99
, why?
Look,
a
in ASCII code it is97
andb
in ASCII it is98
.By doing the
OR
you are doing theOR
of97
and98
in binary, that is,1100001 OR 1100010
=1100011
, that is99
.Edit: If you print the result by formatting it, instead of showing the ascii code we see that it shows the
c
(ascii value99
)*I have changed the println to printf and I have formatted it