Question

In: Computer Science

Develop a python program to convert two decimal numbers (A and B) to binary numbers. You...

Develop a python program to convert two decimal numbers (A and B) to binary numbers. You should generate B complement signal (flip all the bits of Input B,

Solutions

Expert Solution

# Function to convert decimal number

# to binary using recursion

def DecimalToBinary(num,l):

    

    

    if num > 1:

        DecimalToBinary(num // 2,l)

    l.append(str(num % 2))

    return l

def flip_B_bits(l):

    for i in range(len(l)):

         if l[i] =="0":

             l[i] ="1"

         else:

             l[i] = "0"

    print("after fliping bits B is")

    print(''.join(l))

             

# Driver Code

if __name__ == '__main__':

    

    # decimal value

    print("enter value of A")

    A = int(input())

    num=[]

    # Calling function

    DecimalToBinary(A,num)

    print(''.join(num))

    print("enter value of B")

    B= int(input())

    num=[]

    DecimalToBinary(B,num)

    print(''.join(num))

    flip_B_bits(num)





Related Solutions

Write a program to convert the input numbers to another number system. 1. Decimal to Binary...
Write a program to convert the input numbers to another number system. 1. Decimal to Binary 2. Binary to Decimal 3. Hexadecimal to Decimal 4. Decimal to Hexadecimal 5. Binary to Hexadecimal 6. Hexadecimal to Binary The user will type in the input number as following: Binary number : up to 8 bits Hexadecimal number: up to 2 bytes Decimal number: Less than 256 As a result, print out the output after the conversion with their input numbers. The program...
Convert these numbers from Decimal to Binary 111: 66: 252 11 20 Convert these numbers from...
Convert these numbers from Decimal to Binary 111: 66: 252 11 20 Convert these numbers from Binary to Decimal 00110110 11111000 00000111 10101010 What is the Default Subnet mask of Class A IPV4 What is the Default Subnet mask of Class B IPV4 What is the Default Subnet mask of Class C IPV4 What is the CIDR notation or / short handwriting of Subnet masks: Class A: /?. Explain the reason Class B: /? Explain the reason Class C: /?...
1.convert the following numbers from decimal to binary assuming seven-bit twe's complement binary representation: a)49 b)...
1.convert the following numbers from decimal to binary assuming seven-bit twe's complement binary representation: a)49 b) -27 c)0 d) -64 e) -1 f) -2 g) what is the range for this computer as written in binary and in decimal? 2.convert the following numbers from decimal to binary assuming nine-bit twe's complement binary representation: a)51 b) -29 c) -2 d)0 e) -256 f) -1 g ) what is the range for this computer as written in binary and in decimal?
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
Convert the binary numbers to decimal. Show a single sample calculation for the first number (10010010)....
Convert the binary numbers to decimal. Show a single sample calculation for the first number (10010010). 0111 1111 1001 0110 0101 1100 1100 0111
Convert the following unsigned numbers to the requested form: 01100001 binary to: hex, and also decimal...
Convert the following unsigned numbers to the requested form: 01100001 binary to: hex, and also decimal Hex: Decimal: b) 136 decimal to: hex, and also binary Hex: Binary:
(a) Convert the decimal numbers, 70 and -26 to binary in the signed 2’s complement system....
(a) Convert the decimal numbers, 70 and -26 to binary in the signed 2’s complement system. Make sure there are enough digits in the results to be able to perform arithmetic operations with these two numbers. (b) Perform in the signed 2’s complement system, (+70) + (-26) (c) Perform in the signed 2’s complement system, (-70) - (-26) (d) Perform in the signed 2’s complement system, (+70) + (+26)
write a python code to Determine the binary and decimal representations of the following hexadecimal numbers....
write a python code to Determine the binary and decimal representations of the following hexadecimal numbers. Store answers in the appropriate variables in the .py file. (a) 0xfca1 (b) 0xc4d8
Convert the following binary values to hexadecimal and decimal (1 pt each) Write Hex Numbers as...
Convert the following binary values to hexadecimal and decimal (1 pt each) Write Hex Numbers as 0x##(ex 0x0A, 0xFF) Binary Hexadecimal Decimal 0001-1011 0x 0000-1000 0000-0100 0000-1001 0001-1111 1001-1001 0111-1010 1100-0010 1110-0101 1000-1010 0011-0100 0001-1001 0100-0011 1111-1111 1110-0111 0001-0010 0100-1000 0100-1110 1001-0001 0110-1100 Name: Convert the following hexadecimal values to binary and decimal Write binary numbers as 0000-0000 Hexadecimal Binary Decimal 0xf1 0xac 0x56 0x6c 0x32 0x30 0x05 0x28 0xf0 0x07 0x42 0xb9 0x6d 0x2f 0x71 0x0e 0x2d 0xfb 0xba...
Convert the decimal number, 315.56 into binary form?
Convert the decimal number, 315.56 into binary form?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT