binary « string « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » string » binary 

1. long <-> str binary conversion    stackoverflow.com

Is there any lib that convert very long numbers to string just copying the data? These one-liners are too slow:

def xlong(s):
    return sum([ord(c) << e*8 for e,c in enumerate(s)])

def ...

2. How to concatenate strings with binary values in python?    stackoverflow.com

What's the easiest way in python to concatenate string with binary values ?

sep = 0x1
data = ["abc","def","ghi","jkl"]
Looking for result data "abc0x1def0x1ghi0x1jkl" with the 0x1 being binary value not string "0x1".

3. Getting a specific bit value in a byte string    stackoverflow.com

There is a byte at a specific index in a byte string which represents eight flags; one flag per bit in the byte. If a flag is set, its corresponding bit ...

4. Convert IP address string to binary in Python    stackoverflow.com

As part of a larger application, I am trying to convert an IP address to binary. Purpose being to later calculate the broadcast address for Wake on LAN traffic. I am ...

5. How to read String in java that was written using python’s struct.pack method    stackoverflow.com

out.write( struct.pack(">f", 1.1) );
out.write( struct.pack(">i", 12) );
out.write( struct.pack(">3s", "abc") );
how to import struct package in java it says ..
no package found when i am trying to execute it
so ...

6. Python - Flipping Binary 1's and 0's in a String    stackoverflow.com

I'm trying to take a binary number in string form, and flip the 1's and 0's, that is, change all of the 1's in the string to 0's, and all of ...

7. Interpret strings as packed binary data, Python vs Java    stackoverflow.com

I'm struggling a bit with binary in Java and Python to translate a program In python when I execute the following commands, I've got

>>> print ord(pack('>H', 32809)[0])
128

>>> print ord(pack('>H', 32809)[1])
41
In Java, I ...

8. Writing a Binary String to a file    stackoverflow.com

I am writing a huffman encoding program to compress a text file. I converted the text file to its huffman encoded value, and I need to write it to a file. ...

9. Identify the number of elements in a python struct/pack fmt string?    stackoverflow.com

When using the python struct module on can specify a format string that declares how binary data should be interpreted:

>>> from struct import *
>>> fmt = 'hhl'
>>> values = [1,2,3]
>>> blob ...

10. Reading parts of binary data in a string in Python    stackoverflow.com

When you use the .read(n) method on a file object in python you get n amount of bytes back. What if I first load a file in a string, is there some ...

11. Converting PySerial Readline From String to Binary    stackoverflow.com

I'm sending the bytestring 0x0F, 0x07, 0x55, 0x55, 0x55 from a PIC microcontroller. Over the serial port with Python I am using the readlines() command in PySerial. I receive:

['\x0f\x07UUU']
This does indeed correspond ...

12. Estimating the Size of Binary Data encoded as a B64 String in Python    stackoverflow.com

So I have some Binary data in python (a jpg Image, in this case) that I am retreiving from an API as a B64 encoded string. Is there an easy way ...

13. convert huffman code string to binary    stackoverflow.com

I am having problem with how to convert huffman encoding string to binary python. This question involves nothing of the huffman algorithm. It is like this: I can get an encoded huffman string, say ...

14. Write a string of 1's and 0's to a binary file?    stackoverflow.com

I want to take a string of 1's and 0's and convert it into an actual binary file(simply writing the string of 1's and 0's to a file would just make ...

15. converting binary string into float    stackoverflow.com

I have an object that I am storing bits in.

class Bitset:
    def __init__(self, bitstring):
        self.bitlist = []
    ...

16. In Python, how do I convert a .exe file to a string of 1s and 0s?    stackoverflow.com

I seem to be able to find information on how to do this in C#, but not on how to perform the same operation in Python. Any advice or suggestions would be ...

17. Binary string comparison    stackoverflow.com

I'm just learning python and the best way to learn a language is to use it, so I thought I'd make a script that compares binary words to determine which ones ...

18. StringIO with binary files?    stackoverflow.com

I seem to get different outputs:

from StringIO import *

file = open('1.bmp', 'r')

print file.read(), '\n'
print StringIO(file.read()).getvalue()
Why? Is it because StringIO only supports text strings or something?

19. Python reading file in binary, binary data to string?    stackoverflow.com

I'm trying to learn Python and currently doing some exercises online. One of them involves reading zip files. When I do:

import zipfile
zp=zipfile.ZipFile('MyZip.zip')
print(zp.read('MyText.txt'))
it prints:
b'Hello World'
I just want a string with "Hello World". I ...

20. Binary string in Python issues    stackoverflow.com

For some reason I'm having a heck of a time figuring out how to do this in Python. I am trying to represent a binary string in a string variable, and all ...

21. Python: String of 1s and 0s -> binary file    stackoverflow.com

I have a string of 1's and 0's in Python and I would like to write it to a binary file. I'm having a lot of trouble with finding a good ...

22. How to define a binary string in Python in a way that works with both py2 and py3?    stackoverflow.com

I am writing a module that is supposed to work in both Python 2 and 3 and I need to define a binary string. Usually this would be something like data = ...

23. Difference between binary string, byte string, unicode string and an ordinary string (str)    stackoverflow.com

I'm a little confused. In Python what is the difference between a binary string, byte string, unicode string and a plain old string (str)? I'm using Python 2.6.

24. Number to binary string    bytes.com

25. Convert string to 8-bit binary    dreamincode.net

This is what I have so far. I can take the string and convert each character into an integer, and create a list of the integers. Converting each integer into a hypothetical list such as [1,0,0,1,1,0,1,1] is where I'm stuck. Any advice or tips would be greatly appreciated. Thanks in advance! p.s I am trying to work in base 2. def ...

26. [solved] String to Binary or oct    python-forum.org

[solved] String to Binary or oct by vtrzzzzzz Fri Dec 09, 2011 11:37 pm Greetings, I just studied Python and it looks interesting, and complicated though. I want to know how to convert a string to Binary number or Octal number. The following is my code so far: Code: Select all def converter (n, n2): stop_count ...

27. reading strings from binary file    python-forum.org

spark wrote:Always seems to happen ... I discover the answer About half the time, when I am about to go ask someone my question (via the forum or however else), I figure out the answer to my question as I'm documenting everything I've tried, how there's nothing left for me to try, and whatever else. Yeah, i find most of my ...

28. String based Decimal to Binary    python-forum.org

29. Finding XOR checksum of binary string    python-forum.org

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.