binary

how to convert string to binary integer file using command line under linux

What i want is to take an integer represented as a string, for example "1234", and convert it to a file called int, containing a 32-bit big endian integer, with the value 1234. The only way I have figured out to do this is something like echo 1234 | awk '{printf "0: %08X", $1}' | xxd -r > int which is a bit nasty! Does anyone know a...

Sending binary data to (Rails) RESTful endpoint via JSON/XML?

Hello there, I am currently putting together a rails-based web application which will only serve and receive data via json and xml. However, some requirements contain the ability to upload binary data (images). Now to my understanding JSON is not entirely meant for that... but how do you in general tackle the problem of receiving bina...

How can i split a binary in erlang

What I want is, I think, relatively simple: > Bin = <<"Hello.world.howdy?">>. > split(Bin, "."). [<<"Hello">>, <<"world">>, <<"howdy?">>] Any pointers? ...

SQL: Get value at index in binary value

Is there a SQL command that could be used in a query, stored procedure, function, that would work against a Binary Type similar to the following C# code? if (someBinaryArray[index] == 0) { ... I'm wanting to check if an index of a position in the binary is a certain value instead of pulling the entire array down and doing the compari...

Most binary combinations from 4 bits - with each bit able to change state only once

I have 4 binary bits Bit 3 Bit 2 Bit 1 Bit 0 Normally the answer is simple: 2^4, or 16 different combinations; and it would looks something like the following: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 However, The LSB (Bit 0) changes state every iteration I need an algorithm where the state ...

How to work with the data in Binary in C/C++

Hello, I have to do some work work with integers, but I am interested in treat them as binary data, in a way that for example I can take the 4 most significant bits of an 32 bit value. What I am trying to do is, I have several 32 bit value I want to take for example, in the first one 4 bits, the second one 6 bits and the last one 22 bit...

Programming Problem - Fax Compression

I'm preparing to go to a computer science contest by completing problems from past contests. Most of them are pretty easy, but this one is bugging me...it seems simple but I'm just not being able to do it. If you have a string of ones and zeros: 100111010001111100101010 What would be the code to take that as an input and then output ...

Fast read/write from file in delphi

I am loading a file into a array in binary form this seems to take a while is there a better faster more efficent way to do this. i am using a similar method for writing back to the file. procedure openfile(fname:string); var myfile: file; filesizevalue,i:integer; begin assignfile(myfile,fname); filesizevalue:=GetFileSize(fn...

Strange behaviour of .NET binary serialization on Dictionary<Key, Value>

I encountered a, at least to my expectations, strange behavior in the binary serialization of .NET. All items of a Dictionary that are loaded are added to their parent AFTER the OnDeserialization callback. In contrast List does the other way. This can be really annoying in real world repository code, for example when you need to add som...

How to explicity tell SVN to treat a file as text, not binary

I have a number of files that I checked into SVN without having set up their Mime types correctly. SVN initially classified them as binary. I've since set their Mime type in SVN via propset to "text/plain; charset=UTF-8" and I'vc made sure that all the files are UTF-8 signed. When I do 'svn blame filename', svn says that the file is b...

Detecting single one-bit streams within an integer

I have to check a number if it satisfies the following criteria: in binary, all one-bits must be successive. the number must have at least one bit set. the successive one-bits may start at the MSB or end at the LSB, so it's perfectly valid if the number is made up of a single one-bit stream followed by a zero-bit stream or vice versa....

Most efficient way to convert BCD to binary

I have the code below to convert a 32 bit BCD value (supplied in two uint halves) to a uint binary value. The values supplied can be up to 0x9999, to form a maximum value of 0x99999999. Is there a better (ie. quicker) way to achieve this? /// <summary> /// Convert two PLC words in BCD format (forming 8 digit number) into sin...

What is the best way to learn about twiddling with binary data?

What is the best way to learn about twiddling with binary data? Mainly what I'm referring to here is learning to reading/writing file existing file formats that are in binary. I saw one of my co-workers today trying to learn how to create a flash file from scratch, and he was writing a whole bunch of ones and zeros, but I'm guessing ...

Java code or lib to decode a binary-coded decimal (BCD) from a String

I have a string consisting of 1's ('\u0031') and 0's('\u0030') that represents a BCD value. Specifically, the string is 112 characters worth of 1's and 0's and I need to extract either 8 or 16 of these at a time and decode them from BCD to decimal. Ideas? Packages? Libs? Code? Snooty remarks about my sheer fucking laziness? All is welc...

Binary data with pyserial(python serial port)

serial.write() method in pyserial seems to only send string data. I have arrays like [0xc0,0x04,0x00] and want to be able to send/receive them via the serial port? Are there any separate methods for raw I/O? I think I might need to change the arrays to ['\xc0','\x04','\x00'], still, null character might pose a problem. ...

Floating Point to Binary Value(C++)

I want to take a floating point number in C++, like 2.25125, and a int array filled with the binary value that is used to store the float in memory (IEEE 754). So I could take a number, and end up with a int num[16] array with the binary value of the float: num[0] would be 1 num[1] would be 1 num[2] would be 0 num[3] would be 1 and so o...

New to Java - Converting to Binary, Counting 1's, Recursive

Hey Everyone I just started Data Structures and Algorithms which is taught in Java. So far I've only learned C++ in my life so I'm still VERY new to using java. Anyways I have a homework problem I'm a little stuck on: Write a recursive method that returns the number of 1's in the binary representation of N. Use the fact that this is e...

Solution with mulitple projects dependant on the same binary reference

I have a solution with 10 projects. Many of the project depend on a third party dll call foo.dll. The issue is that when i upgrade foo, somehow in Visual studio when i go to object browser it shows me 2 versions of foo.dll how can i find out which project is referencing the old version of foo.dll so i can upgrade it so there is only on...

How can i convert hex numbers to binary in c++?

I am taking a beginning c++ class, and would like to convert letters between hex representations and binary. I can manage to print out the hex numbers using: for(char c = 'a'; c <= 'z'; c++){ cout << hex << (int)c; } But I can't do the same for binary. There is no std::bin that I can use to convert the decimal numbers to binary. H...

How do I convert a binary string to a number in Perl?

How can I convert the binary string $x_bin="0001001100101" to its numeric value $x_num=613 in Perl? ...