binaryreader

Reading IBM floating-point in C++ [duplicate]

心不动则不痛 提交于 2019-12-13 23:03:42
问题 This question already has an answer here : IBM Single Precision Floating Point data conversion to intended value (1 answer) Closed 10 months ago . I have a a binary file format with a bunch of headers and floating point data. I am working on a code that parses the binary file. Reading the headers was not hard but when I tried to read the data I ran into some difficulties. I opened the file and read the headers as the following: ifs.open(fileName, std::ifstream::in | std::ifstream::binary);

How do I check if the uploaded file has the right format? [duplicate]

情到浓时终转凉″ 提交于 2019-12-13 07:21:13
问题 This question already has answers here : Determine if uploaded file is image (any format) on MVC (10 answers) Closed 3 years ago . I work with c# and asp.net I created a webpage with a web form where you enter your information in order to submit it. There is also a file upload on my page: <asp:FileUpload ID="FileUploadPassfoto" runat="server"/> In my c# code behind i coded a IF-Loop which checks if something got uploaded. Like this: if (FileUploadPassfoto.HasFile == true) { HttpPostedFile

Read binary file from a zip file from C# without unzipping it

拈花ヽ惹草 提交于 2019-12-12 09:49:07
问题 I would like to read a binary file from a zip file without unzipping it . The zip file structure: zipFolderName/subFolder/BinFile In the BinFile, I have: Id1, id2, value1 // id1, id2 are string, value1 is int In C#: ZipEntry binFileName = …; // it has been got from zipFile entries MemoryStream ms = new MemoryStream(); binFileName.Extract(ms); using (BinaryReader reader = new BinaryReader(ms)) { string id1 = reader.ReadString(); // error popped here string id2 = reader.ReadString(); int value1

BinaryReader - Reading a Single “ BIT ”?

不打扰是莪最后的温柔 提交于 2019-12-07 17:31:35
问题 Case : Again trying to capture packets through my NIC, I have developed 2 Extensions to use in capturing variable number of bits public static string ReadBits ( this BinaryReader Key , int Value ) { BitArray _BitArray = new BitArray ( Value ); for ( int Loop = 0 ; Loop > Value ; Loop++ ) { /* Problem HERE ---> */ _BitArray [ Loop ] = Key . ReadBoolean ( ); } return BitConverter . ToString ( _BitArray . ToByteArray ( ) ); } public static byte [ ] ToByteArray ( this BitArray Key ) { byte [ ]

BinaryReader - Reading a Single “ BIT ”?

筅森魡賤 提交于 2019-12-05 22:04:56
Case : Again trying to capture packets through my NIC, I have developed 2 Extensions to use in capturing variable number of bits public static string ReadBits ( this BinaryReader Key , int Value ) { BitArray _BitArray = new BitArray ( Value ); for ( int Loop = 0 ; Loop > Value ; Loop++ ) { /* Problem HERE ---> */ _BitArray [ Loop ] = Key . ReadBoolean ( ); } return BitConverter . ToString ( _BitArray . ToByteArray ( ) ); } public static byte [ ] ToByteArray ( this BitArray Key ) { byte [ ] Value = new byte [ ( int ) Math . Ceiling ( ( double ) Key . Length / 8 ) ]; Key . CopyTo ( Value , 0 );

Binary Reader and Writer open at same time?

…衆ロ難τιáo~ 提交于 2019-12-05 16:54:46
I'm writing code that deals with a file that uses hashes. I need to read a chunk, then hash it, then write it, then read another chunk, etc. In other words, I need to do a lot of reading and writing. I'm sure this is really simple, but I just wanted to run it by the pros... Is it possible, and acceptable to do something like: BinaryReader br = new BinaryReader (File.OpenRead(path)); BinaryWriter bw = new BinaryWriter (File.OpenWrite(path)); br.dostuff(); bw.dostuff(); I remember running into some sort of conflicting file streams error when experimenting with opening and writing to files, and I

Decompress byte array to string via BinaryReader yields empty string

一笑奈何 提交于 2019-12-04 21:22:19
问题 I am trying to decompress a byte array and get it into a string using a binary reader. When the following code executes, the inStream position changes from 0 to the length of the array, but str is always an empty string. BinaryReader br = null; string str = String.Empty; using (MemoryStream inStream = new MemoryStream(pByteArray)) { GZipStream zipStream = new GZipStream(inStream, CompressionMode.Decompress); BinaryReader br = new BinaryReader(zipStream); str = br.ReadString(); inStream.Close(

BinaryReader ReadString specifying length?

一笑奈何 提交于 2019-12-04 01:45:00
问题 I'm working on a parser to receive UDP information, parse it, and store it. To do so I'm using a BinaryReader since it will mostly be binary information. Some of it will be strings though. MSDN says for the ReadString() function: Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time. And I completely understand it up until "seven bits at a time" which I tried to simply ignore until I started testing. I'm creating my own byte

EndOfStream for BinaryReader

放肆的年华 提交于 2019-12-04 01:26:31
BinaryReader does not have EndOfStream property. Is it safe to use following code to check if end of stream is reached? reader.BaseStream.Length>reader.BaseStream.Position It depends. There are various stream types that do not implement the Length or Position property, you'd get a NotSupportedException. NetworkStream for example. Of course, if you'd use such a stream then you really do have to know up front how often to call the BinaryReader.Read() method. So, yes, it's fine. The easiest way I found is to check the returned value of the BinaryReader's PeekChar() method. If it returns -1, then

Faster (unsafe) BinaryReader in .NET

送分小仙女□ 提交于 2019-12-02 17:33:59
I came across a situation where I have a pretty big file that I need to read binary data from. Consequently, I realized that the default BinaryReader implementation in .NET is pretty slow. Upon looking at it with .NET Reflector I came across this: public virtual int ReadInt32() { if (this.m_isMemoryStream) { MemoryStream stream = this.m_stream as MemoryStream; return stream.InternalReadInt32(); } this.FillBuffer(4); return (((this.m_buffer[0] | (this.m_buffer[1] << 8)) | (this.m_buffer[2] << 0x10)) | (this.m_buffer[3] << 0x18)); } Which strikes me as extremely inefficient, thinking at how