binary-data

Reading and writing integers to a binary file using C?

情到浓时终转凉″ 提交于 2019-12-11 04:55:52
问题 I am trying to write 100 integers to binary file. I have tried writing to this file, and reading from it. When reading from it I get completely random digits. Here is the block concerning the write. Do note I have the file open for write with "wb" mode. I have also closed the file at the end. for (int i = 0; i < 99; i++) { fwrite(&i, sizeof(int), 1, file); } Here is the block concerning the read. Do note I do have the file open here in "rb" mode and it is closed. int num; for (int i = 0; i <

What config file format to use for user-friendly strings of arbitrary bytes?

核能气质少年 提交于 2019-12-11 03:10:50
问题 So I made a short Python script to launch files in Windows with ambiguous extensions by examining their magic number/file signature first: https://superuser.com/a/317927/13889 https://gist.github.com/1119561 I'd like to compile it to a .exe to make association easier (either using bbfreeze or rewriting in C), but I need some kind of user-friendly config file to specify the matching byte strings and program paths. Basically I want to put this information into a plain text file somehow: magic

Access command line arguments as bytes in python3 [duplicate]

爷,独闯天下 提交于 2019-12-11 02:58:20
问题 This question already has answers here : sys.argv as bytes in Python 3k (2 answers) Closed last year . Is it possible to access the raw argv elements binary content ? $ python3 -c'import sys;print(sys.argv);' `echo -ne "\xff\x80\x00\xff"` ['-c', '\udcff\udc80\udcff'] 回答1: You can obtain the argv contant as bytes as follows: #!/usr/bin/python3 import sys arg1_bytes = sys.argv[1].encode(sys.getfilesystemencoding(), 'surrogateescape') Source: PEP 383 - Non-decodable Bytes in System Character

Using Data.Binary.decodeFile, encountered error “demandInput: not enough bytes”

元气小坏坏 提交于 2019-12-11 02:10:08
问题 I'm attempting to use the encodeFile and decodeFile functions in Data.Binary to save a very large datastructure so that I don't have to recompute it every time I run this program. The relevant encoding- and decoding-functions are as follows: writePlan :: IO () writePlan = do (d, _, bs) <- return subjectDomain outHandle <- openFile "outputfile" WriteMode ((ebsP, aP), cacheData) <- preplanDomain d bs putStrLn "Calculated." let toWrite = ((map pseudofyOverEBS ebsP, aP), pseudofyOverMap cacheData

SQL Server : what is best datatype to store MD5 hash?

試著忘記壹切 提交于 2019-12-10 23:57:37
问题 I need to store in SQL Server a list of items uniquely identified by a hash. In C# I compute my hash as MD5 hash of concatenation of the item ids ( Guid ). Currently, my hash has datatype byte[] in C# , and binary(16) in SQL Server. Here's the DDL : CREATE TABLE [dbo].[ItemSet]( [GUID] [uniqueidentifier] NOT NULL, [HashCode] [binary](16) NOT NULL, [Item1GUID] [uniqueidentifier] NOT NULL, [Item2GUID] [uniqueidentifier] NOT NULL, ... [UtcModified] [datetime] NULL, CONSTRAINT [ItemSet_PK]

Byte to signed int in C

北城余情 提交于 2019-12-10 17:49:00
问题 I have a binary value stored in a char in C, I want transform this byte into signed int in C. Currently I have something like this: char a = 0xff; int b = a; printf("value of b: %d\n", b); The result in standard output will be "255", the desired output is "-1". 回答1: Replace: char a = 0xff by signed char a = 0xff; // or more explicit: = -1 to have printf prints -1 . If you don't want to change the type of a , as @veer added in the comments you can simply cast a to (signed char) before

How to convert binary string to the byte array of 2 bytes in java

此生再无相见时 提交于 2019-12-10 13:20:34
问题 I have binary string String A = "1000000110101110" . I want to convert this string into byte array of length 2 in java I have taken the help of this link I have tried to convert it into byte by various ways I have converted that string into decimal first and then apply the code to store into the byte array int aInt = Integer.parseInt(A, 2); byte[] xByte = new byte[2]; xByte[0] = (byte) ((aInt >> 8) & 0XFF); xByte[1] = (byte) (aInt & 0XFF); System.arraycopy(xByte, 0, record, 0, xByte.length);

C/C++: is it possible to pass binary data through the console? [duplicate]

放肆的年华 提交于 2019-12-10 10:22:51
问题 This question already has answers here : What is the simplest way to write to stdout in binary mode? (2 answers) Closed 4 years ago . I would like to know if it is possible that an utility yields binary data (i.e. graphical images) and outputs them through IO console, while another application, instructed about the nature of those data and informed of the number of the incoming bytes, is able to read it from IO console. 回答1: Yes, it is possible. While it's true that often stdin / stdout are

General question about Binary files

我的未来我决定 提交于 2019-12-10 03:21:09
问题 I am a beginner and I am having trouble in grasping binary files. When I write to a file in binary mode (in python), I just write normal text. There is nothing binary about it. I know every file on my computer is a binary file but I am having trouble distinguishing between files written in binary mode by me and files like audio, video etc files that show up as gibberish if I open them in a text editor. How are files that show up as gibberish created? Can you please give an example of a small

Fast way to read interleaved data?

末鹿安然 提交于 2019-12-10 02:50:00
问题 I've got a file containing several channels of data. The file is sampled at a base rate, and each channel is sampled at that base rate divided by some number -- it seems to always be a power of 2, though I don't think that's important. So, if I have channels a , b , and c , sampled at divders of 1, 2, and 4, my stream will look like: a0 b0 c0 a1 a2 b1 a3 a4 b2 c1 a5 ... For added fun, the channels can independently be floats or ints (though I know for each one), and the data stream does not