image

the sleepy snake

index :: num

module num

Various number crunching methods


The num module defines the following errors:

NumError

The num module defines the following constants:

HEX_DIGITSstring [1-9a-f]
HEX_PREFIXES('0x', '0X', '&H', '&h')

The num module defines the following classes:

BitArrayclass implementing a bit array

The num module defines the following functions:

types

bits

DWORD(num)casts a number or string to a DWORD
WORD(num)casts a number or string to a WORD
UBYTE(num)casts a number or string to a UBYTE
bit_set(n, integer)sets a bit in the integer
bit_clear(n, integer)clears a bit in the integer
bit_is_set(n, integer)checks if a bit is set in the integer
bit_toggle(n, integer)toggles a bit in the integer

bytes

loword(dword)returns the loword of a DWORD
hiword(dword)returns the hiword of a DWORD
lobyte(word)returns the lobyte of a WORD
hibyte(word)returns the hibyte of a WORD
makelong(word1, word2)combines two WORDs to a DWORD
makeword(byte1, byte2)combines two bytes to a WORD
htonl(DWORD)taken from socket module
htons(WORD)taken from socket module
ntohl(DWORD)taken from socket module
ntohs(WORD)taken from socket module

conversions

bin_to_int(bin)converts an string representing a binary number to an integer
int_to_bin(integer)converts an integer to a string representing a binary number
to_base(to_base, num, base=10)converts a number or string to a number of the desired base

hex

prefix(num, prefix='0x')prefixes a number
unprefix(num, prefixes=HEX_PREFIXES)removes the prefix from a number