当前位置:网站首页>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.
边栏推荐
- Cve-2022-23131 - bypass SAML SSO authentication
- How to deploy locally developed SAP ui5 applications to ABAP servers
- JSON. toJSONString(object, SerializerFeature.WriteMapNullValue); Second parameter action
- Period to string [repeat] - period to string [duplicate]
- 北京网上开股票账户安全吗?
- Why study discrete mathematics
- The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars
- How do I turn off word wrap in iterm2- How to turn off word wrap in iTerm2?
- Derivation of COS (a+b) =cosa*cosb-sina*sinb
- ACWING2013. 三条线
猜你喜欢

Laravel8+ wechat applet generates QR code

CTFSHOW

How to deploy locally developed SAP ui5 applications to ABAP servers

After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling

Brief introduction and use of JSON

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

Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things

ACWING/2004. 錯字

Can TCP syn handshake messages transmit data

Exercise: completion
随机推荐
百度地图——入门教程
2022 AI trend 8 forecast!
Cs8683 (120W mono class D power amplifier IC)
JD 8 fleet stores search history, deletes history, clears history (not finished)
Brief introduction and use of JSON
Cannot activate inspection type when SAP retail uses transaction code mm41 to create commodity master data?
DataX tutorial (10) - hot plug principle of dataX plug-in
Understand what MSS is
What is the slice flag bit
Difference between rest and WebServices
Analysis report on investment and financing status and operation benefits of global and Chinese dental industry (2022 Edition)
Laravel8+ wechat applet generates QR code
Metauniverse in 2022: robbing people, burning money and breaking through the experience boundary
Introduction to sap ui5 tools
Record of friend guide
delphi-UUID
keil debug查看变量提示not in scope
Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution
STL map的用法
sin(a-b)=sina*cosb-sinb*cosa的推导过程