当前位置:网站首页>Power representation in go language
Power representation in go language
2022-06-25 06:38:00 【Python's path to becoming a God】
About Go The power of language means
1 cause
Rigid contact Go After language , Start using Go Algorithm problem , Want to write a 2 Of 3 Power , Find out C Linguistic 2^3 It's not working
a := 2 ^ 3
The running result is 1 Not what you want 8
2 reason
It was only after checking that ,Go Symbols in language “ ^ ” No longer used to power , It means “ Bitwise exclusive or operation ”, The specific operation rules are as follows :
Bitwise XOR (^) : One for 0, One for 1 , The result is 1 , Otherwise 0( Bits represent binary machine code ), Examples are as follows :
2 ^ 3
2 Complement 0000 0010
3 Complement 0000 0011
2 ^ 3 0000 0001 => 1
therefore Go In language 2 ^ 3 = 1 instead of 8( Be careful : Computers operate according to complement )
3 Go To the power of
3.1 In general
Go Language to achieve the calculation of power , We call math.Pow function ,math.Pow(x, y) So we can find out x Of y Power .
With 2 Of 3 Power as an example :
a := math.Pow(2, 3)

3.2 A special case
When asked 2 Of n In the second place , We can use Go Left shift operator of language << , Realize left shift operation .
The operation rule of shift left is shift left N position , It's times 2 Of N Power . Examples are as follows :
3.2.1 Move left <<
a := 1 << 3 // 2 Of 3 Power *1
The result is shown in Fig. :
b := 1 << 6 // 2 Of 6 Power *1 64
c := 4 << 2 // 2 Of 2 Power *4 16
d := 4 << 3 // 2 Of 3 Power *4 32
Since there is a left shift , Then there is a right shift
3.2.2 Move right >>( expand )
The operation rule of shift right is shift right N position , Is divided by 2 Of N Power . Example :
a := 16 >> 3 // 16 Divide 2 Of 3 Power
Running results :
3.2.3 principle
stay Golang in , Bit operators are mainly used for binary operations of numeric types .
- Bitwise And The operation rule is , If the binary bits corresponding to both numbers are 1, So the result is 1, Otherwise, the result is 0.
- Bitwise or The operation rule is , If one of the binary bits corresponding to two numbers is 1, So the result is 1, Otherwise, the result is 0.
- Bitwise Exclusive or The operation rule is that if the corresponding binary bits of two numbers are different , So the result is 1, Otherwise, the result is 0.
边栏推荐
- Analysis of common interview questions in redis
- How to create a handy vs Code?
- BGP - basic concept
- Face++ realizes face detection by flow
- Advantages and disadvantages of using SNMP and WMI polling
- How to configure log4j to only keep log files for the last seven days?
- fastadmin 联级清空数据
- How do I turn off word wrap in iterm2- How to turn off word wrap in iTerm2?
- Comparison test of mono 120W high power class D power amplifier chip cs8683-tpa3116
- HCIP Day 16
猜你喜欢

直接选择排序和快速排序

Derivation of sin (a+b) =sina*cosb+sinb*cosa

有能力的人从不抱怨大环境!
![[core content and derivation] the mystery of human memory system may be just like this](/img/7c/98f27bb55a1a3b74c0ed8fd7fd2cc5.jpg)
[core content and derivation] the mystery of human memory system may be just like this

General test point ideas are summarized and shared, which can be directly used in interview and actual software testing
![[200 opencv routines of youcans] 104 Motion blur degradation model](/img/a9/8841ffc8bd3c486bc4011a1a84ff45.jpg)
[200 opencv routines of youcans] 104 Motion blur degradation model

How to use asemi FET 7n80 and how to use 7n80

Ht7180 3.7V L 12v/2a built in MOS high current boost IC solution

cos(a-b)=cosa*cosb+sina*sinb的推导过程

ACWING/2004. 錯字
随机推荐
Derivation of sin (a+b) =sina*cosb+sinb*cosa
DataX tutorial (09) - how does dataX achieve speed limit?
At the age of 26, I was transferred to software testing with zero foundation. Now I have successfully entered the job with a monthly salary of 12K. However, no one understands my bitterness
How two hosts in different network segments directly connected communicate
Sleep quality today 67 points
Ht513 I2S input 2.8W mono class D audio power amplifier IC
JD 7 head search navigation layout
Metauniverse in 2022: robbing people, burning money and breaking through the experience boundary
How to create a handy vs Code?
2022-02-19: fence installation. In a two-dimensional garden, there are some trees represented by (x, y) coordinates. As the installation cost is very expensive, your task is to enclose all the trees w
Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]
VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
How do I check swift if two arrays contain the same elements, regardless of the order in which they appear?
Advantages and disadvantages of using SNMP and WMI polling
Personal blog system graduation project opening report
Talk about TCP and UDP
Wechat applet authorization login + mobile phone sending verification code +jwt verification interface (laravel8+php)
cos(a+b)=cosa*cosb-sina*sinb的推导过程
sin(a+b)=sina*cosb+sinb*cosa的推导过程