Question

In: Computer Science

Convert to binary 73

Convert to binary 73

Solutions

Expert Solution

Algorithm:

  1. Find the remainder of the number by dividing it by 2 and store it in an array.
  2. Divide the number by 2.
  3. Repeat the above two steps until the number is greater than 0.
  4. Now reverse the resulting array. It will be the binary representation.   

Have a look at the below code. I have put comments wherever required for better understanding.

def dec_to_bin(n):
  # create an array to store remainders
  res = []
  # run a loop while n is greater than 0
  while (n>0):
    # store the remainder
    res.append(str(n%2))
    # divide n by 2
    n = n//2 
  # reverse the array
  res.reverse()
  # return the binary number
  return "".join(res) 

Happy Learning!


Related Solutions

Convert 290.2 to binary
Convert 290.2 to binary
How to convert binary to hex?
How to convert binary to hex?
SUBJECT: CYBER ESSENTIALS Convert between binary and hexadecimal values Question 7: Convert binary number to a...
SUBJECT: CYBER ESSENTIALS Convert between binary and hexadecimal values Question 7: Convert binary number to a hexadecimal number Binary number: 00001100 Hexadecimal value: ?? Question 8: Convert binary number to a hexadecimal number Binary number: 01001111 Hexadecimal value: ?? Question 9: Convert binary number to a hexadecimal number Binary number: 10101101 Hexadecimal value: ?? Question 10: Convert hexadecimal number to an 8 bit binary number Hexadecimal number: AB 8 bit binary number: Question 11: Convert hexadecimal number to an 8...
Convert 110.7510 to binary ______ and hexadecimal ______. Show the answer in both binary and hexadecimal....
Convert 110.7510 to binary ______ and hexadecimal ______. Show the answer in both binary and hexadecimal. There are ____________ kilobytes in a megabyte. Convert -13210 to a 16-bit 2’s complement in binary ____________ and hexadecimal ______________.
Convert the decimal number, 315.56 into binary form?
Convert the decimal number, 315.56 into binary form?
i need to convert decimal to twos complement binary and then add the binary digits but...
i need to convert decimal to twos complement binary and then add the binary digits but I am unable to do it. I am only allowed to use string, can anyone help me out please. i need the code urgently. #include #include #include #include using namespace std; string reverse(string s) { string x = ""; for (long i = s.length() - 1; i >= 0; i--) { x += s[i]; } return x; } string twosComplementStringsAddition(string A, string B) {...
Convert the following values into binary numbers for each word and place the binary values in...
Convert the following values into binary numbers for each word and place the binary values in the two-dimensional array in their proper order of words. Value Binary Number Equivalent Word 0 462,91210 Word 1 1142008 Word 2 5420h Word 3 20,992d Word 4 1104208 Word 5 6102008 Word 6 9F88h Word 7 20,49610 Word 8 502416 Word 9 1101018 Word 10 71082h
6. Convert numbers as requested. SHOW YOUR WORK Convert 2B7 (base 16) to binary. Convert 0B2C...
6. Convert numbers as requested. SHOW YOUR WORK Convert 2B7 (base 16) to binary. Convert 0B2C (base 16) to binary. Convert -47 (base 10) to binary 8-bit signed-magnitude. Convert -52 (base 10) to binary 8-bit signed-magnitude. Convert -47 (base 10) to binary 8-bit one's complement. Convert -52 (base 10) to binary 8-bit one's complement. Convert -39 (base 10) to 8-bit binary using excess 127 notation. Convert -61 (base 10) to 8-bit binary using excess 127 notation.
1. Convert to binary and hexadecimal (PLEASE SHOW WORK) a. 35 - binary: - hexadecimal: b....
1. Convert to binary and hexadecimal (PLEASE SHOW WORK) a. 35 - binary: - hexadecimal: b. 85 - binary: - hexadecimal: c. 128 - binary: - hexadecimal: d. 4563 - binary: - hexadecimal:
For the first three sections assume unsigned integers. Convert to binary and hexadecimal 85 4563 Convert...
For the first three sections assume unsigned integers. Convert to binary and hexadecimal 85 4563 Convert from binary to decimal and hexadecimal. 0b1010 1011 0b0011 0001 Convert from hexadecimal to binary and decimal. 0xB2 0x11
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT