About 110,000 results
Open links in new tab
  1. python - Converting binary to decimal integer output - Stack …

    There is actually a much faster alternative to convert binary numbers to decimal, based on artificial intelligence (linear regression) model: Train an AI algorithm to convert 32-binary number to decimal based. Predict a decimal representation from 32-binary. See example and time comparison below:

  2. Convert decimal to binary in python - Stack Overflow

    Aug 20, 2010 · For the sake of completion: if you want to convert fixed point representation to its binary equivalent you can perform the following operations: Get the integer and fractional part. from decimal import * a = Decimal(3.625) a_split = (int(a//1),a%1) Convert the fractional part in its binary representation. To achieve this multiply successively by 2.

  3. Converting integer to binary in Python - Stack Overflow

    The Python package Binary Fractions has a full implementation of binaries as well as binary fractions. You can do your operation as follows: from binary_fractions import Binary b = Binary(6) # Creates a binary fraction string b.lfill(8) # Fills to length 8 This package has many other methods for manipulating binary strings with full precision.

  4. python - Convert to binary and keep leading zeros - Stack Overflow

    I'm trying to convert an integer to binary using the bin() function in Python. However, it always removes the leading zeros, which I actually need, such that the result is always 8-bit: Example: bin(1) -> 0b1 # What I would like: bin(1) -> 0b00000001 Is there a way of doing this?

  5. python - Convert base-2 binary number string to int - Stack …

    Aug 28, 2016 · In this way, you can convert between {binary, octal, hexadecimal, decimal} to {binary, octal, hexadecimal, decimal} by changing right side of colon[:]:#b -> converts to binary :#o -> converts to octal :#x -> converts to hexadecimal :#0 -> converts to decimal as above example Try changing left side of colon to have octal/hexadecimal/decimal.

  6. Python: Binary To Decimal Conversion - Stack Overflow

    Dec 1, 2012 · Convert binary string to int. How would I convert this binary value '101011111' to decimal form in Python? The function converts binary numbers into decimal numbers. Inputs: string b: a binary number. Outputs: int d: a decimal representation of b. def Binary_to_Decimal(b): #what needs to be filled in return d

  7. Convert int to binary string in Python - Stack Overflow

    Jun 3, 2023 · Python has no easy way to produce these binary representations. You can use numpy to turn Two's complement binary values into python integers: >>> import numpy as np >>> np.int8(0b11011011) -37 >>> np.uint8(0b11011011) 219 >>> np.uint8(0b00100101) 37 >>> np.int8(0b00100101) 37 But I don't know an easy way to do the opposite with builtin functions.

  8. Converting Binary to Decimal in python (without built in binary ...

    Nov 16, 2017 · It all seemed very advanced. We have been working in Python and each week we are prompted to write a program. I have been working with this problem for over a week and am having a hard time even starting. The prompt is to read an integer containing only 1's and 0's, process the binary number digit by digit and report the decimal equivalent.

  9. Python: Decimal to Binary - Stack Overflow

    Jul 19, 2016 · 1- the input value is not decimal, binary, hex, or anything else: it is a positive integer (you can pass it using a literal in any base you like e.g., 0xa, 0b1010, 0o12, 10, etc).

  10. python - Convert an integer to binary without using the built-in …

    Nov 23, 2012 · def get_binary_list_from_decimal(integer, bits): '''Return a list of 0's and 1's representing a decimal type integer. Keyword arguments: integer -- decimal type number. bits -- number of bits to represent the integer.

Refresh