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 ...
|
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".
|
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
|
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. ... |
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 ...
|
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
I have an object that I am storing bits in.
class Bitset:
def __init__(self, bitstring):
self.bitlist = []
...
|
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 ... |
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 ... |
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?
|
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 ... |
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 ... |
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 ... |
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 = ... |
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.
|
|
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 ... |
[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 ... |
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 ... |
|
|