Click here to Skip to main content
15,885,278 members

8 bytes data reading from binary file

April2004 asked:

Open original thread
Dear all,

I think it is simple program. But I really face problem and tired out of finding solution. So, I really need your help.

Here is the problem.
I saved 7E FF FF FF FF FF FF 7E (8 bytes) data in binary file.
I would like to retrieve it as reverse order with binary file.

The following is output function.
C++
void outputint64(int i) {
	__int64 app1 = (__int64)mem[i+3] << 48; //mem is short type array data read from binary file
	__int64 app2 = (__int64)mem[i+2] << 32;
	__int64 app3 = (__int64)mem[i+1] << 16;
	__int64 app4 = (__int64)mem[i];
	__int64 app = (__int64)app1 | (__int64)app2 | (__int64)app3 | (__int64)app4;
	printf("int64 value is : %I64x", app);
}


app1 output is 0x 7E FF 00 00 00 00 00 00 //the output is as I expect
app2 output is 0x FF FF FF FF 00 00 00 00 //actually I only expect 0x 00 00 FF FF 00 00 00 00
app3 output is 0x FF FF FF FF FF FF 00 00 //actually I only expect 0x 00 00 00 00 FF FF 00 00
app4 output is 0x FF FF FF FF FF FF FF 7E //actually I only expect 0x 00 00 00 00 00 00 FF 7E

So, app output becomes 0x FF FF FF FF FF FF FF 7E, even though I expect as 0x 7E FF FF FF FF FF FF 7E.

How should I modify to get the expected result?
If you have any idea, please help me.

Thanks in advance.
Tags: C++

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900