python bitwise operators
<int> = <int> & <int>                    # And (0b1100 & 0b1010 == 0b1000).
<int> = <int> | <int>                    # Or  (0b1100 | 0b1010 == 0b1110).
<int> = <int> ^ <int>                    # Xor (0b1100 ^ 0b1010 == 0b0110).
<int> = <int> << n_bits                  # Left shift (>> for right).
<int> = ~<int>                           # Not (also: -<int> - 1).
bitwise operators python
bitwise operators python
Source: edube.org
bitwise operation in python
"""
 BITWISE OPERATION FILE: MAINTAINING CRUD BITWISE OPERAITON;

"""


def getBit(number, shift):
    """
    GET_BIT: RETURN PARTICULAR BIT OF NUMBER PLACED AT 'i' POSITION;
    """
    if number and shift >= 0:
        mask = number >> shift
        return (mask & 1)
    else:
        return None


def setBit(number, position):
    """
    SET_BIT: RETURN PARTICULAR BIT OF NUMBER PLACED AT 'i' POSITION;
    """
    if number and (position >= 0):
        mask = 1 << position
        return (mask | number)
    else:
        return None


def clearBit(number, position):
    """
    CLEAR_BIT: CLEAR PARTICULAR BIT OF NUMBER PLACED AT 'i' POSITION;
    """
    if number and (position >= 0):
        mask = ~(1 << position)
        return mask & number
    else:
        return None


def updateBit(number, position, value):
    """
    UPDATE_BIT: UPDATE PARTICULAR BIT OF NUMBER PLACED AT 'i' POSITION;
    """
    if (number and (position >= 0) and (value == 0 or 1)):
        ## Mask that ha set bit at particular place;
        mask = ~(1 << position)
        return (number & mask | value << position)
    else:
        return None


def clearBitTillPosition(number, position):
    """
    CLEAR_BIT_TILL_POSITION: DELETE ALL BIT TILL POSITION 'K';
    """
    if (number and (position >= 0)):
        mask = -1 << position
        return mask & number
    else:
        return None


def removeBitRange(number, start, end):
    """
    REMOVE_BIT_RANGE: DELETE ALL BIT FROM INDEX START TO END;
    """
    if (number and start >= 0 and end >= 0):

        leftMask = ~0 << end + 1

        rightMask = (1 << start) - 1

        mask = leftMask | rightMask

        return mask & number
    else:
        return None


## COUNT THE SET BIT IN NUMBER HACK;
def countBitHack(number):
    if number != None:
        count = 0
        while (number > 0):
            number = (number & number - 1)
            count += 1

        return count
    else:
        return None


## COUNT THE SET BIT IN NUMBER;
def countBit(number):
    if number != None:
        count = 0
        while (number > 0):
            count += number & 1
            number = number >> 1

        return count
    else:
        return None


## POWER OF 2
def powerOfTwo(number):
    if number == 0:
        return 0
    elif number > 0:
        if (number & number - 1) == 0:
            return True
        return False
    else:
        return False


## FAST EXPONENTIAL OF NUMBER;
def fastExpo(num, pow):
    if (num and pow):
        result = 1  # result = 1
        while (pow > 0):
            lastBit = (pow & 1)  # bit = 11001
            if lastBit:
                result = result * num
            num = num * num
            pow = (pow >> 1)

        return result
    else:
        return None


## CONVERT INTEGER TO BINARY;
def convertIntToBin(number):
    base = 10
    pow = 1
    result = 0
    while (number > 0):
        lastBit = number & 1  ## Taking Out Last Bit;
        result += lastBit * pow
        pow = pow * base
        number = number >> 1  ## Removing Bits From Left;
    print(result)


## CHECK EVEN OR ODD IN NUMBER;
def evenOrOdd(number=None) -> bool:
    dataType = type(number)
    if dataType == list:
        for num in number:
            if (num & 1):
                print(f"Num {num} is Odd")
            else:
                print(f"Num {num} is Even")
    elif dataType == int:
        if (number & 1):
            print(f"Num {number} is Odd")
        else:
            print(f"Num {number} is Even")
    else:
        return False

    return True


## FLIP ALL SET TO UNSET BIT;
def flipAllBits(num):
    return (~num)^num


## FLIP 32BIT INTEGER;
def flip32BitInterger(num):
    return (2**32-1)^num

Python相关代码片段

pathlib python

pandas excelwriter

python practise

key,value en python

linear regression in tensorflow

spark dataframe get column

drop one table sqlalchemy

python code to remove last character from string

fastapi get body on http middleware

custom neural network in keras

python selenium execute_script

db model for blog

yolov5 opencv

Get first 100 lines of file - python

python playground

print number pattern using for loop in python

ollama python

no module named 'wget'

No module named 'langchain'

failed to build wxpython

python vs c#

rabbitmq python example

change the django url prefix name

np.linspace is not defined python

LLM beguiner guide python

python parquet file to csv

python best practices

yolov5 without net

save variable as pkl python

python [-9:]

eigenface python

'DataFrame' object has no attribute 'dtype'

unable to enable maximize window tkinter

rabbit and fox numpy python

lstm in keras

neural network in keras

resnet50 in keras

autoencoder in keras

cnn in keras

tensor in keras

pyTelegramBotAPI edit photo

print api python

how to get values but not index from pandas series

how to get mode of a column from pandas

bayesian neural network pymcmc

lda python

back propagation python

logical syntax is not none python

register model django

Descending Selection sort

Selection sort with while loops

Selection sort with for loops

Doubling Algorithm for cluster analysis in python

Tkinter widgets

nameerror: name 'callable' is not defined

NameError: name 'Union' is not defined

Make a widget customtkinter python

nn module pytorch

import tf python

Spark SEssion object

Implement Bubble sort with while loops

Unoptimized bubble sort algorithm

Optimized bubble sort algorithm

how to get today's date in python

st_aggrid install

python venv pip blocked by admin windows

numpy matrix from lists of different leght

python postgres auto commit

dotenv install python

np mean axis

LinkExtractor Object

admin django documentation

Python native Convolution implementation

is django monolithic

what is function call with an llm

np array to series

dht22 micropython pico

disable slash command discord.py

python docker compose not printing

tabnet probabilities