raw byte representation of unsigned long long?

W

wenmang

Hi,
I encountered a problem involving storage of unsigned long long. The
requirement of incoming data field is an unsigned 64-bit integer, but
on our system, due to lack of support of 64-bit integer from Oralce
pro-C(it only supports 32-bit integer). We have to find a way to get
around it. I am wondering whether there is other way to store big int
in kind of 8-byte raw data and later convert it to 64-bit integer. Is
the raw data has to be stored as C-string? Certainly, we can use
double, but I like to know whether we have other option or not. thx
 
F

fermineutron

Hi,
I encountered a problem involving storage of unsigned long long. The
requirement of incoming data field is an unsigned 64-bit integer, but
on our system, due to lack of support of 64-bit integer from Oralce
pro-C(it only supports 32-bit integer). We have to find a way to get
around it. I am wondering whether there is other way to store big int
in kind of 8-byte raw data and later convert it to 64-bit integer. Is
the raw data has to be stored as C-string? Certainly, we can use
double, but I like to know whether we have other option or not. thx

why not to use array of bytes or ints.
I dont know your implementation, tell me, how do yu get your data? do
you pass a pointer to a 64bit int to a function which stores the int in
that memeory, or perhaps a function returns a pointer to a long long
data type?

In eaither case the two things which have to be accounted for are:
1) your program must allocate sufficient storage for data. 64 bits can
be allocated by a cast of
long long int A;

or by a cast of
long int A[2];
or
char A[8]
in all cases the address of A points to 8 bytes of memory.
in case 1 your pointer is
p=&A;
in case 2 and 3
p=&A[0];

What ever implementation of C you are using, if it does not support 64
bit numbers, you have to trace back to the code where the data gets
stored into a 64 bit number and insdead of storing it as a single
number you will store it into array, using what ever data types your
implementation supports.
 
U

Ulrich Eckhardt

fermineutron said:
1) your program must allocate sufficient storage for data. 64 bits can
be allocated by a cast of
long long int A;
Wrong.

or by a cast of
long int A[2];
Wrong.

or
char A[8]

Also wrong.

In particular the second case will fail on any LP64 system (i.e. most 64
bit systems) where a Long and a Pointer are 64 bit wide - those systems
are even common. The other two are wrong because long long is at least 64
bit, not exactly 64 bit and because char might have more than eight bits.

Since C99, uint8_t exist on platforms that have an unsigned, 8 bit integer.
Similarly, uint64_t exists. On substandard compilers, a typedef to one of
these names is still better than using a long and assuming it is 64 bit in
size.

Uli
 
R

Richard Heathfield

fermineutron said:

1) your program must allocate sufficient storage for data. 64 bits can
be allocated by a cast of
long long int A;
Wrong...


or by a cast of
long int A[2];
....wrong...

or
char A[8]

....and wrong.

I suggest you learn C before trying to teach it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
W

wenmang

Now, the question still remains, how do I do it?

Richard said:
fermineutron said:

1) your program must allocate sufficient storage for data. 64 bits can
be allocated by a cast of
long long int A;
Wrong...


or by a cast of
long int A[2];
...wrong...

or
char A[8]

...and wrong.

I suggest you learn C before trying to teach it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
I

Ian Collins

Hi,
I encountered a problem involving storage of unsigned long long. The
requirement of incoming data field is an unsigned 64-bit integer, but
on our system, due to lack of support of 64-bit integer from Oralce
pro-C(it only supports 32-bit integer). We have to find a way to get
around it. I am wondering whether there is other way to store big int
in kind of 8-byte raw data and later convert it to 64-bit integer. Is
the raw data has to be stored as C-string? Certainly, we can use
double, but I like to know whether we have other option or not. thx
Switching compilers would appear to be the best advice offered. You
mention "later convert it to 64-bit integer", so I assume you have
another compiler with 64 bit support?
 
R

Richard Heathfield

(e-mail address removed) said:
Now, the question still remains, how do I do it?

You can store anything you like in an array of unsigned char. If you have N
bits to store, you will need an array of unsigned char that is at least
(N + CHAR_BIT - 1) / CHAR_BIT bytes in size.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top