binaryfiles

Reading 32 bit signed ieee 754 floating points from a binary file with python?

我的未来我决定 提交于 2019-11-29 06:09:30
问题 I have a binary file which is simple a list of signed 32 bit ieee754 floating point numbers. They are not separated by anything, and simply appear one after another until EOF. How would I read from this file and interpret them correctly as floating point numbers? I tried using read(4) , but it automatically converts them to a string with ascii encoding. I also tried using bytearray but that only takes it in 1 byte at a time instead of 4 bytes at a time as I need. 回答1: struct.unpack('f', file

are “seekp” & “seekg” interchangeable?

耗尽温柔 提交于 2019-11-29 02:59:17
Well I just noticed that by changing the position -in microsoft visual studio- through "seekp" I implicitelly also change the read-position, when handling files. I am wondering however if this is "portable" behaviour? Can I expect the position of reading & writing to be always the same? And consequently: will tellp & tellg always return the same value? For file positions they are the same. In other words there is only one pointer maintained. From 27.9.1.1p3 : A joint file position is maintained for both the input sequence and the output sequence. So, seekg and seekp are interchangeable for

How to check if the file is a binary file and read all the files which are not?

断了今生、忘了曾经 提交于 2019-11-29 02:48:32
How can I know if a file is a binary file? For example, compiled c file. I want to read all files from some directory, but I want ignore binary files. Use utility file , sample usage: $ file /bin/bash /bin/bash: Mach-O universal binary with 2 architectures /bin/bash (for architecture x86_64): Mach-O 64-bit executable x86_64 /bin/bash (for architecture i386): Mach-O executable i386 $ file /etc/passwd /etc/passwd: ASCII English text $ file code.c code.c: ASCII c program text file manual page I use ! grep -qI . $path Only drawback I can see is that it will consider an empty file binary but then

C# checking for binary reader end of file

不羁岁月 提交于 2019-11-29 00:54:51
I was searching for a way to check whether I've reached the end of a file for my binary reader and one suggestion was to use PeekChar as such while (inFile.PeekChar() > 0) { ... } However, it looks like I've run into an issue Unhandled Exception: System.ArgumentException: The output char buffer is too sma ll to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'Syste m.Text.DecoderReplacementFallback'. Parameter name: chars at System.Text.Encoding.ThrowCharsOverflow() at System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothin gDecoded) at System.Text

python get unicode string size

大憨熊 提交于 2019-11-28 23:18:49
I have a binary file. This file contains an UTF-8 string. Moreover, it is guaranteed that this string is just a single word. In python, how can I get number of letters in this string? Let's say, I opened this file and read bytes: bytes = open("1.dat", "rb").read() What next have I to do to find out length (in letters, not bytes) of UTF-8 string? unicode_string = bytes.decode("utf-8") print len(unicode_string) 来源: https://stackoverflow.com/questions/8056496/python-get-unicode-string-size

How to get the width/height of jpeg file without using library?

旧街凉风 提交于 2019-11-28 21:39:28
问题 Firstly I want to say I tried many times to find the answer by using google search, and I found many results but I did not understand, because I don't know the idea of reading a binary file, and convert the value that Obtained to readable value. What I tried doing it. unsigned char fbuff[16]; FILE *file; file = fopen("C:\\loser.jpg", "rb"); if(file != NULL){ fseek(file, 0, SEEK_SET); fread(fbuff, 1, 16, file); printf("%d\n", fbuff[1]); fclose(file); }else{ printf("File does not exists."); } I

How to read little endian integers from file in C++?

末鹿安然 提交于 2019-11-28 21:31:06
Say I have a binary file; it contains positive binary numbers, but written in little endian as 32-bit integers How do I read this file? I have this right now. int main() { FILE * fp; char buffer[4]; int num = 0; fp=fopen("file.txt","rb"); while ( fread(&buffer, 1, 4,fp) != 0) { // I think buffer should be 32 bit integer I read, // how can I let num equal to 32 bit little endian integer? } // Say I just want to get the sum of all these binary little endian integers, // is there an another way to make read and get sum faster since it's all // binary, shouldnt it be faster if i just add in binary

Evaluating HDF5: What limitations/features does HDF5 provide for modelling data?

柔情痞子 提交于 2019-11-28 17:27:05
We are in evaluating technologies that we'll use to store data that we gather during the analysis of C/C++ code. In the case of C++, the amount of data can be relatively large, ~20Mb per TU. After reading the following SO answer it made me consider that HDF5 might be a suitable technology for us to use. I was wondering if people here could help me answer a few initial questions that I have: Performance. The general usage for the data will be write once and read "several" times, similar to the lifetime of a '.o' file generated by a compiler. How does HDF5 compare against using something like an

Modifying contents of Android .aar file / Converting to and from .zip format

拈花ヽ惹草 提交于 2019-11-28 17:03:59
So I have a .aar file which has a file I need to remove from inside it. I am running on mac and changed the extention from .aar to .zip and unzipped the zip file. I then removed the file from the folder, recompressed it back into a .zip and then tried changing the extension from .zip back to .aar. The problem is that the now modified .aar is not recognized as a .aar file. It is still being registered as a .zip and I can no longer use it in my project. So my question is two fold: 1) How can one easily modify the contents of a .aar file and 2) How do you properly convert to/from .aar and .zip?

Transform a hex info to binary using linux command

孤街醉人 提交于 2019-11-28 15:46:26
I have this binary file on my linux system .. udit@udit-Dabba ~ $ cat file.enc Salted__s�bO��<0�F���Jw!���]�:`C�LKȆ�l Using hexdump command I see its information like this .. udit@udit-Dabba ~ $ hexdump -C file.enc 00000000 53 61 6c 74 65 64 5f 5f 1b 73 a1 62 4f 15 be f6 |Salted__.s.bO...| 00000010 3c 30 cc 46 ee 10 13 11 84 bf 4a 77 21 a4 84 99 |<0.F......Jw!...| 00000020 0e 5d ef 11 18 3a 60 43 a0 4c 4b 1e c8 86 e6 6c |.]...:`C.LK....l| 00000030 Now I am given a file on some other system whose contents are like this .. 53 61 6c 74 65 64 5f 5f 1b 73 a1 62 4f 15 be f6 3c 30 cc 46 ee 10 13 11