binary-data

Using reinterpret_cast to read file into structure

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-20 04:58:25
问题 struct DATAs { char data1; short data2; short data3; float data4; int data5; short data6; unsigned short data7; short data8; char data9; }; void fixFile(char* filename) { std::ifstream InputFile; InputFile.open(filename, std::ios::binary); DATAs FileDatas; InputFile.read(reinterpret_cast<char*>(&FileDatas), sizeof(FileDatas)); } Why do I need to use "reinterpret_cast" for the reading instead of "InputFile.read(&FileDatas, sizeof(FileDatas))" ? 回答1: The type of the first argument to std:

How to get raw binary data from a POST request processed by Spring?

血红的双手。 提交于 2021-02-16 06:17:06
问题 I need to write an application which would be able to process binary data sent by CUrl, such as: curl localhost:8080/data --data-binary @ZYSF15A46K1.txt I've created a POST processing method as follows: @RequestMapping(method = RequestMethod.POST, value = "/data") public void acceptData(HttpEntity<byte[]> requestEntity) throws Exception { process(requestEntity.getBody()); } However it doesn't seem to be returning raw binary data. I've tried sending a GZip file and after going through Spring

How to get raw binary data from a POST request processed by Spring?

允我心安 提交于 2021-02-16 06:15:49
问题 I need to write an application which would be able to process binary data sent by CUrl, such as: curl localhost:8080/data --data-binary @ZYSF15A46K1.txt I've created a POST processing method as follows: @RequestMapping(method = RequestMethod.POST, value = "/data") public void acceptData(HttpEntity<byte[]> requestEntity) throws Exception { process(requestEntity.getBody()); } However it doesn't seem to be returning raw binary data. I've tried sending a GZip file and after going through Spring

Python: Similar functionality in struct and array vs ctypes

蓝咒 提交于 2021-02-07 22:17:37
问题 Python provides the following three modules that deal with C types and how to handle them: struct for C structs array for arrays such as those in C ctypes for C functions, which necessarily entails dealing with C’s type system While ctypes seems more general and flexible (its main task being “a foreign function library for Python”) than struct and array , there seems to be significant overlap in functionality between these three modules when the task is to read binary data structures. For

Create new column with binary data or presence/absence data in R [duplicate]

我怕爱的太早我们不能终老 提交于 2021-02-05 12:28:45
问题 This question already has an answer here : How to add a factor column to dataframe based on a conditional statement from another column? (1 answer) Closed 7 years ago . The answer to the following question has been addressed more simply than this answer: Create new column with binary data based on several columns I am trying to create a new column of binary data (presence/absence data) based on another column in R . I want "Species_code" rows with the number 101 to produce a 1 in the new

How to migrate firebird DATA blob subtype binary to SQL Server sql_variant using Python?

旧街凉风 提交于 2021-01-29 17:31:28
问题 As part of my records which come back from a Python fdb SQL select query, I get a b"string". I pass it on to SQL Server and execute a call to be stored into a sql_variant column in a SQL Server database. However I get this error: pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC SQL Server Driver]Optional feature not implemented (0) (SQLBindParameter)') Here is the firebird field spec that the b"string" comes out of using fdb. DATA BLOB segment 80, subtype BINARY Nullable I even tried

Read binary file in C# from specific position

蹲街弑〆低调 提交于 2021-01-21 10:20:58
问题 Is it possible to read a large binary file from a particular position? I don't want to read the file from the beginning because I can calculate the start position and the length of the stream I need. 回答1: using (FileStream sr = File.OpenRead("someFile.dat")) { sr.Seek(100, SeekOrigin.Begin); int read = sr.ReadByte(); //... } 回答2: According to @shenhengbin answord. Use BinaryReader.BaseStream.Seek . using (BinaryReader b = new BinaryReader(File.Open("perls.bin", FileMode.Open))) { int pos =

Converting python float to bytes

早过忘川 提交于 2020-12-26 05:00:49
问题 I want to convert a Python float into a byte array, encoding it as a 32 bit little-endian IEEE floating point number, in order to write it to a binary file. What is the modern Pythonic way to do that in Python 3? For ints I can do my_int.to_bytes(4,'little') , but there is no to_bytes method for floats. It's even better if I can do this in one shot for every float in a numpy array (with dtype numpy.float32). But note that I need to get it as a byte array, not just write the array to a file

Silhouette score for Jaccard distance

三世轮回 提交于 2020-12-13 10:55:53
问题 I'm working on a kmeans functionality for a uni assignment. We need to run euclidean clustering on one set of data and then Jaccard on the other. We need to explore a few different models to evaluate the number of clusters and for the Euclidean it was quite straight forward using sklearn.metrics.silhouette_score , but this does not give the option to use Jaccard distance. As such I was wondering if anyone has an idea of how to calculate it for Jaccard distance? I have managed to create a

Store Binary Data in QR Code (ZXING Java Library)

别说谁变了你拦得住时间么 提交于 2020-12-13 07:41:34
问题 My Java program needs to send a binary payload via QR Code, but I can't get it to work. I have tried several QR Code libraries and many approaches, but all seem to have this problem. My current implementation uses ZXING. The problem is that all the Java libraries I've tried seem to be focused on String payloads, and do not provide support for binary data. The common suggested solution to this is to encode the binary data as Base64. However, my data is already near the size limit of QR Codes.