binary

Import a binary image from matlab to a "C" program

I have a binary image in Matlab, and I need the binary array(0 and 1) in a C program, How can I import it? I can save the binary image in Matlab as ".mat" but I don't know how to read the mat file in C. Also I thought maybe I can save the binary image in Matlab as ".bin" which is readable in "C" but again I don't know how to save an ima...

Python write to file

Hello, I've got a little problem here. I'm converting binary to ascii, in order to compress data. All seems to work fine, but when I convert '11011011' to ascii and try to write it into file, I keep getting error UnicodeEncodeError: 'charmap' codec can't encode character '\xdb' in position 0: character maps to Here's my code: b...

How can a bash script write out a binary file, without using uudecode?

Hi all, I've got a little puzzler here for the bash scripting experts... I have a bash script that needs to create a small (80 byte) binary file when it runs. The contents of the file need to be contained inside the script itself (i.e. I don't want to just package the file along with the script). My script currently does it like this:...

Reading binary file into array in Objective-C [iPhone]

Hey I want to read binary file on my iPhone. I have .txt file which stores information about an array: int[6000][9] How can I put this data into an array in my code? I tried this: int mapa1[6000][9]; NSFileHandle* file = [NSFileHandle fileHAndleForReadingAtPAth: @"level1.txt"]; [[file readDataOfLength:4] getBytes:mapa1]; mapa1 = NSSw...

Binary Tree: Longest path between 2 Nodes

Calculate the longest path between two nodes. The path is in an arch. Signature of method is: public static int longestPath(Node n) In the example binary tree below, it is 4 (going thru 2-3-13-5-2). This is what I have right now and for the given tree it just returns 0. public static int longestPath(Node n) { if (n != null) {...

Insert hex values into MySql

I have a table with a VARBINARY column. I need to insert a string such as '4D2AFF' which represents the hex values 0x4D, 0x2A and 0xFF respectively. How do I construct this statement? ...

OpenCL build program from binary

Hello, I'm trying to test the OpenCL functionality of building a program from pre-compiled binaries. So far I've managed to create the binary file, but I'm having trouble to load it. I'm trying to adapt this code for use with the C++ bindings: FILE* fp = fopen("oclLLtoUTM.ptx", "r"); fseek (fp , 0 , SEEK_END); const size_t lSize = ftell...

Hessian with large binary data (java)

Hi! I'am looking for a complete example of large binary data transfer with Hessian (java) caucho implementation. Where can I found one ? Zig ...

Python binary file reading problem

I'm trying to read a binary file (which represents a matrix in Matlab) in Python. But I am having trouble reading the file and converting the bytes to the correct values. The binary file consists of a sequence of 4-byte numbers. The first two numbers are the number of rows and columns respectively. My friend gave me a Matlab function he...

python: c# binary datetime encoding

I need to extract financial price data from a binary file. This price data is normally extracted by a piece of C# code. The biggest problem I'm having is getting a meaningful datetime. The binary data looks like this: '\x14\x11\x00\x00{\x14\xaeG\xe1z(@\x9a\x99\x99\x99\x99\x99(@q=\n\xd7\xa3p(@\x9a\x99\x99\x99\x99\x99(@\xac\x00\x19\x00...

BST preorder traversal and writting tree content to temporary array

I'm trying to write binary search tree's content to temporary array in order to use in main. However I'm not sure how to do it... I have tried something like this: void Book::preorder(TreeNode *ptr, Person &temp[], int x) { if(ptr!=NULL) { temp[x].name=ptr->item.name; x++; preorder(ptr->left, temp, x); preorder(ptr->right, te...

Fortran: Binary Subtraction (is there a binary type?)

I have a homework question regarding operator precedence in Fortran. In order to understand the question I need to know how to use binary numbers in Fortran. Can someone give me an example of how to use binary numbers in fortran? (Specifically with subtraction). ...

Storing/querying binary sequences and searching with masks

I've found a good way to store some data in the database with a binary sequence, like 0b0101000 and find rows that give a positive result after applying a mask. For exemple : SELECT (0b0101010 & (1<<3 | 1<<5))>0; allows me to get rows with the 3rd or 5th bit on, no matter if the others bits are on or off. The problem is when I want to ...

Treat a string as binary in Ruby

I have a string coming from a database, for example 0b0101000. I'd like to cast it to a binary value, in order to apply byte operations on it, like 0b01011000 & (1<<0 | 1<<4) ...

How do you properly void a permission when using Bitwise Permissions?

Alright, Here's the gist of what I'm planning to do. I'm going to have two tables. One with "ranks" or "roles" and one with users. I want to assign permissions on a role/user basis and retract permissions on a user basis. So, just for general purposes lets say that we have $role_can $user_can and $user_cant I know that for specifyin...

How to write chords with MIDI?

Hello! How do I write a chord, i.e. a NoteOn of seveal notes on each above the other at the same time line? What should be the message for this chord. ...

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

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 kindly tell me any suggestions if any Thanking you i took that code from http://stackoverflow.com/questions/1255918/...

Same simple source code, different binaries on Windows

Hi all, I have a question about the source-code binary on Windows. #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; } The same source code, I compiled twice on Windows (VS 2008 Cmmand Prompt: "CL"), but I got different binaries. cl new.cpp Can you guys tell me why, and how to avoid that? Thanks. Pet...

Directly reading large binary file in C# w/out copying

I am looking for the most efficient/direct way to do this simple C/C++ operation: void ReadData(FILE *f, uint16 *buf, int startsamp, int nsamps) { fseek(f, startsamp*sizeof(uint16), SEEK_SET); fread(buf, sizeof(uint16), nsamps, f); } in C#/.NET. (I'm ignoring return values for clarity - production code would check them.) Specifi...

MIDI Program Change event.

Please take a look at Midi Event Commands, where it's explained that some events like Program Change take only one parameter. My question is then what do you send along with this event's 2nd parameter's byte, is it 0x00? or you just entirely omit it from the event which doesn't really make sense? ...