Skip to content

Commit

Permalink
Added '&','|','^' description and example
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdimehrabi committed Dec 6, 2022
1 parent 49b1020 commit cfc66b0
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion content/chapter 1/1.4-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,50 @@ fmt.Println("")



- عملگر `&` به انگلیسی **AND** به فارسی **و** دو مقدار باینری رو با یک دیگر مقایسه و اگر هر بیت مقدار 1 در هر دو طرف داشته باشد آن را 1 نگه میدارد و در غیر اینصورت آن بیت را 0 میکند.
-
- عملگر `|` به انگلیسی **OR** به فارسی **یا** دو مقدار باینری رو با یک دیگر مقایسه و اگر هر بیت مقدار 1 در یک طرف یا هر دوطرف داشته باشد آن را 1 نگه میدارد و در غیر اینصورت آن بیت را 0 میکند.

عملگر `|` به انگلیسی **XOR** به فارسی **نامی ندارد** دو مقدار باینری رو با یک دیگر مقایسه و اگر هر بیت مقدار 1 در هر دوطرف داشته باشد آن را 0 میکند.
```
//& operator example
a := 0b01000101
b := 0b01010100
c := a & b
fmt.Printf("binary:%08b,value:%v", a, a) //binary:01000101,value:69
fmt.Println("")
fmt.Printf("binary:%08b,value:%v", b, b) //binary:01010100,value:84
fmt.Println("")
fmt.Printf("binary:%08b,value:%v", c, c) //binary:01000100,value:68
fmt.Println("\n\n---------------\n")
//| operator example
d := 0b01000101
e := 0b01010100
f := d | e
fmt.Printf("binary:%08b,value:%v", d, d) //binary:01000101,value:69
fmt.Println("")
fmt.Printf("binary:%08b,value:%v", e, e) //binary:01010100,value:84
fmt.Println("")
fmt.Printf("binary:%08b,value:%v", f, f) //binary:01010101,value:85
fmt.Println("\n\n---------------\n")
//^ operator example
g := 0b01000101
h := 0b01010100
i := a ^ b
fmt.Printf("binary:%08b,value:%v", g, g) //binary:01000101,value:69
fmt.Println("")
fmt.Printf("binary:%08b,value:%v", h, h) //binary:01010100,value:84
fmt.Println("")
fmt.Printf("binary:%08b,value:%v", i, i) //binary:00010001,value:17
```




**توضیحات و مثال های سه عملگر & , | و ^ به زودی اضافه خواهند شد **

## اولویت عملگرها
در زبان گو ما یکسری اولویت ها برای عملگرها داریم و همچنین در زبان گو مثل سایر زبان ها پرانتز `()` ترویج دهنده اولویت ها می باشد.
Expand Down

0 comments on commit cfc66b0

Please sign in to comment.