golang 判斷平台是32位還是64位

2022-07-11 19:57:09 字數 523 閱讀 9706

在strconv包中有個常量

const intsize  =  32  <<  (  ^uint(0)  >>  63  )

const intsize = intsize

在32位平台這個值為32;在64位平台,這個值為64; 因此可以通過這個來判斷平台的位數.

原理:在32平台系統:

1. uint(0)在平台底層是0x00000000

2. ^uint(0)在平台底層是0xffffffff

3. ^uint(0) >> 63 在底層平台是0x00000000,也就是0

4. 32 << 0 結果是0

在64平台系統:

1. uint(0)在平台底層是0x0000000000000000

2. ^uint(0)在平台底層是0xffffffffffffffff

3. ^uint(0) >> 63 在底層平台是0x0000000000000001,也就是1

4. 32 << 1 結果是32*2  =  64

非常巧妙!!!

判斷機器 程式是32位還是64位

一 linux上如何知道自己的作業系統 計算機 是32位還是 64位的?linux users should type the uname command.depending on the platform,you may see linux gaylord.stata.com 2.6.11 1.2...

python 判斷Dll是32位還是64位

coding gb2312 writer write by lhsbqb date 2012 07 16 import sys class getdllbit def init self,dll name if len sys.argv 2 獲取 軟體名 print sys.argv 1 decod...

如何判斷Linux是32位還是64位

方法一 getconf long bit 在linux終端輸入getconf long bit命令 如果是32位機器,則結果為32 linux root localhost getconf long bit 32 如果是64位機器,則結果為64 linux root localhost getcon...