MOAL.computer_organization package¶
Submodules¶
MOAL.computer_organization.bcd module¶
MOAL.computer_organization.bit_field module¶
MOAL.computer_organization.bitwise_operations module¶
-
MOAL.computer_organization.bitwise_operations.
DELAY
= 0.4¶ wikipedia.org/wiki/Bitwise_operation#Bitwise_operators
(__)/ – __________/__
*____/|________|> *
-
MOAL.computer_organization.bitwise_operations.
_shift_left
(bits)[source]¶ Shift bits to the left <<<, carrying the bit over to the right; e.g. 0100 << 1000
-
MOAL.computer_organization.bitwise_operations.
_shift_right
(bits)[source]¶ Shift bits to the right >>>, carrying the bit over to the left, which preserves the sign; e.g. 0100 >> 0010
-
MOAL.computer_organization.bitwise_operations.
bitwise_and
(bits1, bits2)[source]¶ Do a logical AND on each pair of bits, by way of multiplication: e.g. 1 x 1 = 1, 0 x 0 / 0 x 1 = 0
-
MOAL.computer_organization.bitwise_operations.
bitwise_not
(bits)[source]¶ NOT is straightforward - a simple one’s complement will do, since the bits are merely flipped.
-
MOAL.computer_organization.bitwise_operations.
bitwise_or
(bits1, bits2)[source]¶ Do a logical OR on each pair of bits: e.g. 1/1 = 1, 0/1 = 1, 0/0 = 0
-
MOAL.computer_organization.bitwise_operations.
bitwise_xor
(bits1, bits2)[source]¶ Do a logical XOR on each pair of bits: e.g. 1/1 = 0, 0/1 = 1, 0/0 = 0
-
MOAL.computer_organization.bitwise_operations.
rotate_through_carry
(bits)[source]¶ Like circular, but the end bits are stored as flags.
MOAL.computer_organization.data_types module¶
-
class
MOAL.computer_organization.data_types.
BaseDataType
[source]¶ Bases:
object
The irony here is that these data types take up significantly more actual memory as a class representation in a bytecode interpreted language. The classing is merely for intuitive understanding and representing the hierarchy/operations.
-
class
MOAL.computer_organization.data_types.
Bit
(value)[source]¶ Bases:
MOAL.computer_organization.data_types.BaseDataType
-
__init__
(value)¶
-
__str__
()¶
-
-
class
MOAL.computer_organization.data_types.
Byte
(value)[source]¶ Bases:
MOAL.computer_organization.data_types.Nibble
Also sometimes referred to as an Octet
-
__init__
(value)¶
-
-
class
MOAL.computer_organization.data_types.
Halfword
(value)[source]¶ Bases:
MOAL.computer_organization.data_types.Nibble
-
__init__
(value)¶
-
-
class
MOAL.computer_organization.data_types.
Nibble
(value)[source]¶ Bases:
MOAL.computer_organization.data_types.Bit
-
__init__
(value)¶
-
-
class
MOAL.computer_organization.data_types.
Word
(value)[source]¶ Bases:
MOAL.computer_organization.data_types.Nibble
-
__init__
(value)¶
-
-
MOAL.computer_organization.data_types.
bin_dec
(value)¶
-
MOAL.computer_organization.data_types.
bin_inc
(value)¶
MOAL.computer_organization.endianness module¶
-
MOAL.computer_organization.endianness.
DEBUG
= False¶ ‘Endianness’ represents byte ordering when memory is addressed in a computer - little endian stores the smallest byte first, whereas the biggest bit is stored first as big endian.
- See betterexplained.com/articles/
- understanding-big-and-little-endian-byte-order/ for a nice overview.
Also, see linux.die.net/man/3/<function> for real network conversion functions e.g. [htons, htons, ntohl, ntohs]
And see linux.die.net/man/3/endian for base conversion functions e.g. [htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh]
Free online copy of Gulliver’s travels available here: literatureproject.com/gulliver-travel/
Character list: cliffsnotes.com/literature/g/gullivers-travels/character-list
MOAL.computer_organization.factoradic module¶
-
MOAL.computer_organization.factoradic.
DEBUG
= False¶ Factoradic numeral system: en.wikipedia.org/wiki/Factorial_number_system
-
MOAL.computer_organization.factoradic.
factoradic_to_decimal
(*args, **kwargs)[source]¶ Converts a factoradic number to decimal form.
- Args:
- factoradic (int) - the factoradic number to convert
- Returns:
- res (int) - the converted decimal
>>> factoradic_to_decimal('341010') >>> 463
-
MOAL.computer_organization.factoradic.
factpos
(num, pos)[source]¶ Take a number and position and get the position factorial multiplied by the number.
- Args:
- num (int) - the integer number to use pos (int) - the position to find the factorial over
- Returns:
- (int) - the integer result
>>> factpos(2, 2) >>> 4
MOAL.computer_organization.numerical_encoding_basic module¶
-
MOAL.computer_organization.numerical_encoding_basic.
_scale
(base, maximum)[source]¶ Creates a range of numbers up to maximum, given a base. The scale is used as an intuitive reference for visually converting numbers.
See youtube.com/watch?v=e3mCABVEK88 for some good examples.
e.g.
Note: The visual order is reversed, but the returned list is not.
-
MOAL.computer_organization.numerical_encoding_basic.
all_powers_n
(num, power)[source]¶ Powers of two check, extended to any exponent
-
MOAL.computer_organization.numerical_encoding_basic.
all_powers_two
(num)[source]¶ Find the various powers of two for a given num – often used for finding binary values of a num, since binary is base 2.
-
MOAL.computer_organization.numerical_encoding_basic.
bin_to_dec
(num)[source]¶ Convert binary to integer
-
MOAL.computer_organization.numerical_encoding_basic.
bin_to_hex
(num)[source]¶ Convert binary to hexadecimal. Uses integer conversion as an intermediate step.
-
MOAL.computer_organization.numerical_encoding_basic.
bin_to_oct
(binary)[source]¶ Convert binary to octal. Uses integer conversion as an intermediate step.
-
MOAL.computer_organization.numerical_encoding_basic.
compare_to_native
(native, custom, count=20, assert_results=False, prefix=None, supress_other=True)[source]¶ Compares custom numerical converter to the native python version with a list of nums.
-
MOAL.computer_organization.numerical_encoding_basic.
dec_to_bin
(num)[source]¶ Convert integer to binary. Only handles positive integers.
-
MOAL.computer_organization.numerical_encoding_basic.
dec_to_hex
(num)[source]¶ Convert integer to hexadecimal
-
MOAL.computer_organization.numerical_encoding_basic.
dec_to_oct
(num)[source]¶ Convert an integer to an octal, using ‘divide by base’ technique.
-
MOAL.computer_organization.numerical_encoding_basic.
divide_by
(num, base, to_int=False, joined=False)[source]¶ General purpose numeral converter, using the divide-by N + modulo technique. Returns a list of integers, or optionally, a joined string, or a converted list of integers as strings.
-
MOAL.computer_organization.numerical_encoding_basic.
hex_to_bin
(hexnum)[source]¶ Convert hexadecimal to binary
-
MOAL.computer_organization.numerical_encoding_basic.
hex_to_dec
(hexnum)[source]¶ Convert hexadecimal to integer
-
MOAL.computer_organization.numerical_encoding_basic.
hex_to_oct
(hexnum)[source]¶ Convert hexadecimal to octal
-
MOAL.computer_organization.numerical_encoding_basic.
make_groups
(string, count)[source]¶ Make a set of groups with a string.
e.g. >>> make_groups(‘ABCDEFGH’, 2) = [[‘AB’, ‘CD’, ‘EF’, ‘GH’]] Raises ValueError if modulus operation results in uneven group distribution.
-
MOAL.computer_organization.numerical_encoding_basic.
oct_to_bin
(num)[source]¶ Convert octal to binary instructions used for algorithm from: wikipedia.org/wiki/Octal#Octal_to_binary_conversion
-
MOAL.computer_organization.numerical_encoding_basic.
oct_to_dec
(num)[source]¶ Convert an octal to integer. algorithm/notes from robotroom.com/numSystems4.html
-
MOAL.computer_organization.numerical_encoding_basic.
oct_to_hex
(octnum)[source]¶ Convert octal to hexadecimal. Uses binary conversion as an intermediate step. Instructions used for algorithm from: wikipedia.org/wiki/Octal#Octal_to_hexadecimal_conversion
MOAL.computer_organization.one_twos_complement module¶
MOAL.computer_organization.positional module¶
-
MOAL.computer_organization.positional.
dec_to_n
(num, base, alphabet=None)[source]¶ Convert a decimal to any base, using the divide by N technique. See divide_by for details.
-
MOAL.computer_organization.positional.
dec_to_unary
(num)[source]¶ Tally representation e.g. | = 1, / = 5