Number in Base B¶
Conversion of number from one base to another base
NumberBaseB
Bin
oct
Hex
-
simula.base.
Bin
¶ alias of
simula.base.Binary
-
class
simula.base.
Binary
(number)¶ Converts a number from one base into binary.
- Parameters
number – a number
EXAMPLES:
simula : a = Bin(34); a 0b100010 simula : a + a 0b1000100 simula : Bin(4) + Bin(10) 0b1110 simula : Bin(14) 0b1110 simula : Bin(4) + Bin(10) == Bin(14) True
-
simula.base.
Hex
¶ alias of
simula.base.Hexadicimal
-
class
simula.base.
Hexadicimal
(number)¶ Converts a number from one base into hexadecimal base.
- Parameters
number – a number
EXAMPLES:
simula : a = Hex(1000); a 0x3e8 simula : a + a 0x7d0 simula : Hex(400) + Hex(1000) 0x578 simula : Hex(5099) 0x13eb
-
class
simula.base.
NumberBaseB
(number, base=2)¶ Representation of number in some basis.
- Parameters
number – an integer
base – (an integer) the basis
EXAMPLES:
simula : a = NumberBaseB(16, 2); a [1, 0, 0, 0, 0] simula : NumberBaseB(168, 8) [2, 5, 0]
-
to_list
(length=None)¶ Returns a list of size
length
of the representation ofself
.- Parameters
length – (optional) the size of representation of
self
EXAMPLES:
simula :
-
simula.base.
Oct
¶ alias of
simula.base.Octal
-
class
simula.base.
Octal
(number)¶ Converts a number from one base into octal base.
- Parameters
number – a number
EXAMPLES:
simula : a = Oct(100); a 0o144 simula : a + a 0o310 simula : Oct(40) + Oct(60) 0o144 simula : 2Oct(14) 28
-
simula.base.
int_to_base_b
(number, base=2, length=None)¶ Converts an integer from one base into another base for a given length.
- Parameters
number – (an integer) the number to write in some basis
base – (an integer) the basis
length – (optional) the length of the new vector