# bitset **Repository Path**: jszhanghit/bitset ## Basic Information - **Project Name**: bitset - **Description**: Realize the function of bit operation in python,Similar to bitset in C++. - **Primary Language**: Python - **License**: WTFPL - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-04 - **Last Updated**: 2023-03-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # bitset #### 介绍 Realize the function of bit operation in python,Similar to bitset in C++. 具有bit特性的Python数据类型,与C++中bitset功能类似。 ### 初始化 a = bitset(8,0xa5) #初始化为8bit,初始值为0xa5 b = bitset(8) #初始化为8bit,初始值为0 c = bitset(8,0x7c) ### bit操作 temp1 = a&c # 与操作,temp1 为 bitset(8,0x24) temp2 = a|c # 或操作,temp2 为 bitset(8,0xfd) temp3 = a^c #异或操作,temp3为 bitset(8,0xd9) temp4 = a << 1 #左移位 temp4为 bitset(8,0x4a),最高位丢失,最低位补0 temp5 = a >> 1 #右移位 temp5为 bitset(8,0x52),最低位丢失,最高位补0 ### 函数 a.size() # 返回8,a的bit数 a.get_value() # 返回0xa5,a的值 a.count() #返回4,a中为1的bit数目