binary

STL "closest" method?

I'm looking for an STL sort that returns the element "closest" to the target value if the exact value is not present in the container. It needs to be fast, so essentially I'm looking for a slightly modified binary search... I could write it, but it seems like something that should already exist... ...

Convert integer/float to different architecture representations (may be in hex)

Is there any lib witch i can use to convert integers and floats between different architecture representation? ie. -255 with big-endian 2byte signed integer is: 0xff7f and for 4 byte signed integer is 0xffffff7f and same with other... I have found Binary tools package in PEAR, but it status is unmaintained and stopped at 0.3.0 version,...

MySQL Tri-state field

I need to create a good/neutral/bad field. which one would be the more understandable/correct way. A binary field with null (1=good, null=neutral, 0=bad) An int (1=good, 2=neutral, 3=bad) An enum (good, neutral, bad) Any other It's only and informative field and I will not need to search by this. ...

Write Int array to Stream in .NET

Hi, what's the best way to write the binary representation of an int array (Int32[]) to a Stream? Stream.Write only accepts byte[] as source and I would like to avoid converting/copying the array to an byte[] (array but instead streaming directly from the 'original location'). In a more system-oriented language (a.k.a. C++) I would s...

Splitting a binary file on binary delimiter?

I'm working on a shell script to convert MPO stereographic 3D images into standard JPEG images. A MPO file is just two JPEG images, concatenated together. As such, you can split out the JPEG files by finding the byte offset of the second JPEG's magic number header (0xFFD8FFE1). I've done this manually using hexdump/xxd, grep, head, and ...

Socket Programming in c

I have created small socket programs (client/server). Client will transfer all formats of files to server.The problem i am facing now is - I read mp3 file in binary mode and sent to the server. Server reads the content from the buffer and create a file.But when i am trying to open the file, it not getting open. But size remains same as o...

Python: int to binary stream element?

If you have a int and you wish to convert it to a single char string you can use the function chr() Is there a way to convert an int to a single char binary stream? e.g: >>> something(97) b'a' What is the something? ...

compile python script in linux

So I have a python script that relies on a couple modules. Specifically pexpect and pyinoitify. I know you can compile a python script into a .exe in windows, but is there something relatively equivalent in linux? I don't care about it being a binary, I'd just like to be able to distribute my script without requiring the separate install...

Manually construct SQL with binary data in Java.

I have a small program that manually creates queries. In pseudo code, it's basically done like this string[] a = new string[x]; a[0] = "data 1"; a[1] = "data 2"; a[2] = "data 3"; string query = "insert into x (y) values("; for i { query += a[i] + ","; } query += ");"; I'm aware that this usage is sub-optimal and I should do a com...

What does data="@/some/path" mean in Python?

This is from some code I'm looking at... I think it's some sort of special format string that loads the file at the path into a binary string assigned to data, but I'm not sure as when I try to replicate it all I get is a standard string. Or is it actually a standard string and I'm reading too much into it? ...

How can you parse a Java 64-bit long from a binary file into a PHP string?

I've used unpack to convert most of the data types I have in a binary file that I'm parsing with little problems. I have no idea how to work with a big endian 64-bit signed long. I think this data type is stored using 2's complement. The application of the data file I'm reading is a java app so I assume it's 2's complement. I don't need ...

bitwise not (~) operator, clarification needed

Suppose you have the following C code unsigned char a = 1; printf("%d\n", ~a); // prints -2 printf("%d\n", a); // prints 1 I am surprised to see -2 printed as a result of ~1 conversion: Opposite of 0000 0001 is 1111 1110 --> anything but -2 What am i missing here? please advise ...

Finding the maximum area in given binary data...

I have a problem with describing algorithm for finding maximum rectangular area of binary data, where 1 occurs k-times more often than 0. Data is always n^2 bits like this: For example data for n = 4 looks like: 1 0 1 0 0 0 1 1 0 1 1 1 1 1 0 1 Value of k can be 1 .. j (k = 1 means, that number of 0 and 1 is equal). For abov...

How to convert a decimal into binary and vice versa

Hi how to convert Decimal to binary and viceversa i am working on solaris10 platform can anybody help me with a command Decimal to Binary 4000000002-100000000000000000000000000010 Binary to decimal 100000000000000000000000000010-4000000002 ...

C# read binary data from socket

Hello, I'm working on an application that reads and writes binary data from and to a socket. So first I create a socket with TcpClient. But I'm stuck on reading the data from the socket. Are there any code samples on how to read binary data from the socket? Concrete, there are 2 things I don't understand. First, how do I know if a mess...

Binary data within a dll is unmanageable

Currently we store report templates (word docs) as binary arrays within a dll in our C# solution. public readonly static byte[] audit_engagement_template = new byte[] {208,207,17,224,161,177,26,225,0,0,0,0,0,0,0,0,... Etc etc. Now this file has become HUGE and very unmanageable as Visual Studio starts using over 2.5Gb of memory whene...

Useful Binary Diff Tool (other than msdn[apatch and mpatch], xdelta, bsdiff, vbindiff and winmerge)

I need a binary diff tool that can produce a patch file from compared 8MB files (.dat compressed files) and can merge produced said patch file to the older .dat file (size 8MB). I tried using msdn's apatch and mpatch, but mpatch produces 7MB diff or patch file when differentiating two 8MB files, when supposedly, the said patch file shou...

Help installing static binary for wkhtmltopdf

I am trying to use the static binary of wkhtmltopdf on Ubuntu server 10.0.4. The reason for is that it apparently has a built in modified QT that will allow me to run wkhtmltopdf without an X Server. Result: Once installed (see steps below), when I execute wkhtmltopdf in the terminal, it does not fire up... just returns me to the promp...

WPF loading serialized image

Hi, In an app I need to serialize an image through a binarywriter, and to get it in an other app to display it. Here is a part of my "serialization" code : FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write); BinaryWriter bin = new BinaryWriter(fs); bin.Write((short)this.Animations.Count)...

How to copy binary data from one stream to another?

Currently i have a program that loads binary data into a stringstream and then pases the data to a fstream like so: stringstream ss(stringstream::binary | stringstream::in | stringstream::out); ss.write(data, 512); // Loads data into stream // Uses a memory block to pass the data between the streams char* memBlock = new char[512]; ss....