binary

Ruby unpack binary

亡梦爱人 提交于 2021-01-28 11:23:55
问题 I am working on unpacking a binary file for the first time in Ruby. Already found the unpack method which works pretty nice. Which according to the docs works perfect for 8(1 byte),16(2 byte),32(4 byte) and 64 bit(8 byte). But now I have to unpack 5 bytes. How do I do this? Thx in advance! 回答1: To literally unpack five bytes: str.unpack 'C5' That gives you five byte values as unsigned ints. The question is how to reinterpret those ints as a single data type. Pack/unpack only recognize the

incorrect encoding serving binary (pdf) file through ClassPathResource in Spring

旧城冷巷雨未停 提交于 2021-01-28 11:23:06
问题 I have been struggling with the following problem for two days and can not get my head around it. I am trying to serve a static pdf in a Spring Boot rest application. It should be very straight forward but I just cannot get it to work. First I simply placed the pdf in the resource folder and tried to load it directly from the javascript code, like this: var newWindow = window.open(/pdf/test.pdf, ''); That resulted in a new window with a pdf not showing any content. Saving the pdf to disk from

qt binary file writing and reading

僤鯓⒐⒋嵵緔 提交于 2021-01-28 06:34:48
问题 void write(QString filename) { QChar ch('b'); QFile mfile(filename); if (!mfile.open(QFile::WriteOnly) { qDebug() << "Could not open file for writing"; return; } QDataStream out(&mfile); out.setVersion(QDataStream::Qt_4_8); out << ch; mfile.close(); } open binary file and writing 'b'(binary) void read(QString filename) { QFile mfile(filename); if (!mfile.open(QFile::ReadOnly)) { qDebug() << "Could not open file for reading"; return; } QDataStream in(&mfile); in.setVersion(QDataStream::Qt_4_8)

Storing numerical value from a binary file into an array- C++

余生颓废 提交于 2021-01-28 06:13:02
问题 I am trying to read numerical data from a binary file containing 100 double values and store it in an array called myArray. When I print myArray nothing is being shown, as if myArray has never been filled. Any help is appreciated. int main() { int file_len; ifstream infile; infile.open("mybinfile.bin", ios::binary | ios::in); if (!infile.is_open()) { cout << "Error in opening the file. " << endl; } else { const int file_len = 100; std::vector<char> myVect; myVect.resize(file_len); int i = 0;

Converting text to a binary file

最后都变了- 提交于 2021-01-28 06:10:53
问题 I need to convert a text file of the following format to binary: The first line contains the number of products in the inventory, The following lines contains: product name '\t' product price '\t' quantity '\n' (there can be more than one \t between columns) For every product the binary output file will contain an int representing the length of the product name, the chars that hold the product name, an int representing the price and an int representing the quantity. Sample input file: Asus

Search Binary File for a Pattern

 ̄綄美尐妖づ 提交于 2021-01-28 04:00:59
问题 I need to search for a binary pattern in binary file, how can i do it? I tried with "strstr()" function and convert the file and the pattern to a string but its not working. (the pattern is also a binary file) this is what it tried: void isinfected(FILE *file, FILE *sign, char filename[], char filepath[]) { char* fil,* vir; int filelen, signlen; fseek(file, 0, SEEK_END); fseek(sign, 0, SEEK_END); filelen = ftell(file); signlen = ftell(sign); fil = (char *)malloc(sizeof(char) * filelen); if (

simple MySQL binary data inserting

断了今生、忘了曾经 提交于 2021-01-27 21:03:54
问题 I know how to insert String: MySqlConnection connection = new MySqlConnection(); connection .Open(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "INSERT INTO User ('username') VALUE ('David')"); command.ExecuteNonQuery(); connection.Close(); How can I insert binary data using varBinary? 回答1: You can insert string as is - command.CommandText = "INSERT INTO User (username) VALUE ('David')"); Also, you can insert data as a hex value, use Encoding.GetBytes method to

AWS API GATEWAY configuration to return binary pdf file from lambda

孤街浪徒 提交于 2021-01-27 11:58:22
问题 I want to return a pdf from a AWS Lambda function, and I use API Gateway for calling it from a any browser. I have a aws lambda function in c# that returns an API Gateway Response which body is a pdf in base64 encoded string . So far the endpoint returns a file with .pdf extension but not in binary. Instead, is a text file with the base64 string. The headers i'm returning from the c# code are: var headersDic = new Dictionary<string, string>(); headersDic.Add("Content-type", "application/pdf")

Gigabyte or Gibibyte (1000 or 1024)?

妖精的绣舞 提交于 2021-01-26 18:39:42
问题 This may be a duplicate and I apologies if that is so but I really want a definitive answer as that seems to change depending upon where I look. Is it acceptable to say that a gigabyte is 1024 megabytes or should it be said that it is 1000 megabytes? I am taking computer science at GCSE and a typical exam question could be how many bytes in a kilobyte and I believe the exam board, AQA, has the answer for such a question as 1024 not 1000. How is this? Are both correct? Which one should I go

Gigabyte or Gibibyte (1000 or 1024)?

≯℡__Kan透↙ 提交于 2021-01-26 18:38:57
问题 This may be a duplicate and I apologies if that is so but I really want a definitive answer as that seems to change depending upon where I look. Is it acceptable to say that a gigabyte is 1024 megabytes or should it be said that it is 1000 megabytes? I am taking computer science at GCSE and a typical exam question could be how many bytes in a kilobyte and I believe the exam board, AQA, has the answer for such a question as 1024 not 1000. How is this? Are both correct? Which one should I go