"""
CS1122 Homework 3
Austin Vuong N10778545 aav304
"""

def q2 (n): # Convert a number to binary
    binary_num = "{0:08b}".format(n)
    print (binary_num)

q2(57)
q2(123)
q2(85)
q2(38)

def q3 (hex_nums): # Convert a list of hex numbers into a string
    lst = hex_nums.split(' ')
    for item in lst:
        item = str(item)
        value = eval(item)
        char = chr(value)
        print (char, end='')
    print ()

q3('0x41 0x53 0x43 0x49 0x49 0x20 0x77 0x68 0x61 0x74 0x20 0x79 0x6f 0x75 0x20 0x64 0x69 0x64 0x20 0x74 0x68 0x65 0x72 0x65')
q3('0x39 0x41 0x4d 0x20 0x69 0x73 0x20 0x74 0x6f 0x6f 0x20 0x65 0x61 0x72 0x6c 0x79 0x20 0x66 0x6f 0x72 0x20 0x63 0x6c 0x61 0x73 0x73')
q3('0x43 0x6f 0x6d 0x70 0x75 0x74 0x65 0x72 0x73 0x20 0x61 0x72 0x65 0x20 0x6d 0x61 0x67 0x69 0x63')
q3('0x57 0x68 0x61 0x74 0x20 0x74 0x68 0x65 0x20 0x68 0x65 0x78 0x3f')

def q4 (bin_num): # Convert a binary number into a hex number
    hex_num = hex(int(bin_num, 2))
    print (hex_num)

q4('00001011101011101101111010101101')
q4('11001010111111101111101011001110')
q4('10111110111011111101000000001101')
q4('11111111111111111001000001100010')

def q5 (n): # Convert octal to decimal
    n_string = str(n)
    dec_num = 0
    counter = 0
    for i in n_string:
        counter += 1
        i_int = int(i)
        dec_num += i_int * (8 ** (len(n_string) - counter))
    print (dec_num)

q5(10)
q5(42)
q5(77)
q5(113)

642c3a45cb165112b63d40c4e092bc444492842b
<mask token>


def q2(n):
    binary_num = '{0:08b}'.format(n)
    print(binary_num)


<mask token>


def q3(hex_nums):
    lst = hex_nums.split(' ')
    for item in lst:
        item = str(item)
        value = eval(item)
        char = chr(value)
        print(char, end='')
    print()


<mask token>

<mask token>


def q2(n):
    binary_num = '{0:08b}'.format(n)
    print(binary_num)


<mask token>


def q3(hex_nums):
    lst = hex_nums.split(' ')
    for item in lst:
        item = str(item)
        value = eval(item)
        char = chr(value)
        print(char, end='')
    print()


<mask token>


def q4(bin_num):
    hex_num = hex(int(bin_num, 2))
    print(hex_num)


<mask token>

<mask token>


def q2(n):
    binary_num = '{0:08b}'.format(n)
    print(binary_num)


<mask token>


def q3(hex_nums):
    lst = hex_nums.split(' ')
    for item in lst:
        item = str(item)
        value = eval(item)
        char = chr(value)
        print(char, end='')
    print()


<mask token>


def q4(bin_num):
    hex_num = hex(int(bin_num, 2))
    print(hex_num)


<mask token>


def q5(n):
    n_string = str(n)
    dec_num = 0
    counter = 0
    for i in n_string:
        counter += 1
        i_int = int(i)
        dec_num += i_int * 8 ** (len(n_string) - counter)
    print(dec_num)


<mask token>

<mask token>


def q2(n):
    binary_num = '{0:08b}'.format(n)
    print(binary_num)


q2(57)
q2(123)
q2(85)
q2(38)


def q3(hex_nums):
    lst = hex_nums.split(' ')
    for item in lst:
        item = str(item)
        value = eval(item)
        char = chr(value)
        print(char, end='')
    print()


q3('0x41 0x53 0x43 0x49 0x49 0x20 0x77 0x68 0x61 0x74 0x20 0x79 0x6f 0x75 0x20 0x64 0x69 0x64 0x20 0x74 0x68 0x65 0x72 0x65'
    )
q3('0x39 0x41 0x4d 0x20 0x69 0x73 0x20 0x74 0x6f 0x6f 0x20 0x65 0x61 0x72 0x6c 0x79 0x20 0x66 0x6f 0x72 0x20 0x63 0x6c 0x61 0x73 0x73'
    )
q3('0x43 0x6f 0x6d 0x70 0x75 0x74 0x65 0x72 0x73 0x20 0x61 0x72 0x65 0x20 0x6d 0x61 0x67 0x69 0x63'
    )
q3('0x57 0x68 0x61 0x74 0x20 0x74 0x68 0x65 0x20 0x68 0x65 0x78 0x3f')


def q4(bin_num):
    hex_num = hex(int(bin_num, 2))
    print(hex_num)


q4('00001011101011101101111010101101')
q4('11001010111111101111101011001110')
q4('10111110111011111101000000001101')
q4('11111111111111111001000001100010')


def q5(n):
    n_string = str(n)
    dec_num = 0
    counter = 0
    for i in n_string:
        counter += 1
        i_int = int(i)
        dec_num += i_int * 8 ** (len(n_string) - counter)
    print(dec_num)


q5(10)
q5(42)
q5(77)
q5(113)

"""
CS1122 Homework 3
Austin Vuong N10778545 aav304
"""

def q2 (n): # Convert a number to binary
    binary_num = "{0:08b}".format(n)
    print (binary_num)

q2(57)
q2(123)
q2(85)
q2(38)

def q3 (hex_nums): # Convert a list of hex numbers into a string
    lst = hex_nums.split(' ')
    for item in lst:
        item = str(item)
        value = eval(item)
        char = chr(value)
        print (char, end='')
    print ()

q3('0x41 0x53 0x43 0x49 0x49 0x20 0x77 0x68 0x61 0x74 0x20 0x79 0x6f 0x75 0x20 0x64 0x69 0x64 0x20 0x74 0x68 0x65 0x72 0x65')
q3('0x39 0x41 0x4d 0x20 0x69 0x73 0x20 0x74 0x6f 0x6f 0x20 0x65 0x61 0x72 0x6c 0x79 0x20 0x66 0x6f 0x72 0x20 0x63 0x6c 0x61 0x73 0x73')
q3('0x43 0x6f 0x6d 0x70 0x75 0x74 0x65 0x72 0x73 0x20 0x61 0x72 0x65 0x20 0x6d 0x61 0x67 0x69 0x63')
q3('0x57 0x68 0x61 0x74 0x20 0x74 0x68 0x65 0x20 0x68 0x65 0x78 0x3f')

def q4 (bin_num): # Convert a binary number into a hex number
    hex_num = hex(int(bin_num, 2))
    print (hex_num)

q4('00001011101011101101111010101101')
q4('11001010111111101111101011001110')
q4('10111110111011111101000000001101')
q4('11111111111111111001000001100010')

def q5 (n): # Convert octal to decimal
    n_string = str(n)
    dec_num = 0
    counter = 0
    for i in n_string:
        counter += 1
        i_int = int(i)
        dec_num += i_int * (8 ** (len(n_string) - counter))
    print (dec_num)

q5(10)
q5(42)
q5(77)
q5(113)
