Contents

  1. ascii.py
  2. ascii_table.py
  3. binaryToDecimalIterateOverCharacters.py
  4. binaryToDecimalIterateOverExponents.py
  5. binaryToDecimal.py

ascii.py 1/5

[
top][prev][next]
# Conversion of a text message into ASCII
# by Sara Sprenkle

print()
print("This program converts a textual message into a sequence")
print("of numbers representing the ASCII encoding of the message.")
print()

message = input("Enter the message to encode: ")

print()
print("Here are the ASCII codes for '" + message + "':")

for ch in message:
    print(ord(ch), end=" ")

print()

ascii_table.py 2/5

[
top][prev][next]
# Create a table of numbers (ASCII) and their character equivalent
# by Sara Sprenkle

print("This program prints out the ASCII Table")

print("DEC CHAR")
print("-"*3, "-"*4)

for i in range(33, 127):
    print("%3d %4s" % (i, chr(i)))
    

binaryToDecimalIterateOverCharacters.py 3/5

[
top][prev][next]
# Converts a binary number into a decimal.
# Iterates over the characters in the string,
# i.e., from left to right in the string.
# By CSCI111

print("This program converts a binary number into a decimal number.")

# todo: get input from the user
binNum = "10110"
decVal = 0
exponent = len(binNum)

for char in binNum:
    bit = int(char)
    exponent -= 1
    decVal += bit * 2**exponent

print(binNum, "has a decimal value of", decVal)

binaryToDecimalIterateOverExponents.py 4/5

[
top][prev][next]
# Converts a binary number into a decimal.
# Iterates over the exponents,
# i.e., from right to left over the binary number.
# By CSCI111

print("This program converts a binary number into a decimal number.")

# todo: get input from the user
binNum = "10110"
decVal = 0

for exponent in range(len(binNum)):
    index = len(binNum) - (exponent + 1)
    char = binNum[index]
    if char == "1":
        decVal += 2**exponent
    # bit = int(char)
    # decVal += bit * 2 ** exponent

print(binNum, "has a decimal value of", decVal)

binaryToDecimal.py 5/5

[
top][prev][next]
# Converts a binary number into a decimal.
# Iterates over the exponents (i.e., from right to left).
# By CSCI111

print("This program converts a binary number into a decimal number.")

binNum = "10110"
decVal = 0

for exponent in range(len(binNum)):
    index = len(binNum) - (exponent + 1)
    char = binNum[index]
    if char == "1":
        decVal += 2**exponent
    # bit = int(char)
    # decVal += bit * 2 ** exponent

print(decVal)

Generated by GNU Enscript 1.6.6.