E
E
Evgeny Ivanovich2017-02-11 12:46:45
C++ / C#
Evgeny Ivanovich, 2017-02-11 12:46:45

Raw long long bytes to signed long long integer?

Good day. In general, the question is this:
There is a binary in which the long long value is written, and there is a certain "reader" that reads the sequence of the first 8 bytes. When translating the sequence of bytes read into a number, the sign is omitted. How to correctly translate the read sequence of bytes without loss of sign?
ps
The binary is read from a lua script.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-02-11
@Pauk_Code

The sign cannot go down. 64 bits is 64 bits. And how to represent them is the problem of a specific task, not a number.
The most significant bit is usually responsible for the sign. If you interpret it not as a flag, but as a member of the bit depth of the number, then you will have an unsigned number, in the range from 0 to 2 ^ 64. If it is taken into account as a sign bit, then you can get a range from -2 ^ 63 (the most significant bit in one) to 2 ^ 63-1 (the most significant bit in zero).
How to interpret it depends only on what type you choose when reading: signed long long or unsigned long long.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question