F
Fred Ma
Hello,
I want to assign a long int to an unsigned
short int. From what I've read, it will do
what I want, which is to assign as many of
the least significant bits as can fit.
Would I be right in assuming that the
LSBs are used regardless of whether the
sign is preserved?
Just for background, I am using a pair of
long ints returned by Posix's gettimeofday
to initialize erand48's 48-bit pseudorandom
generator. The context problem itself is
not one of ISO C, but the above behaviour
of assigning long to unsigned is (hopefully)
generic enough.
I suspect that the answer is that the bits
are treated as bits, signedness be damned,
and regardless of the numeric representation
(1 or 2's complement, or whatever else might
be out there). For my purposes, that's OK,
since the low order bits are still a good
random seed for when I initialize the
generator many times in quick succession.
I'm not using the standard "time" function
because I may initialize the generator
within 1 second of the last initialization.
Thanks for any confirmation or correction
of this assignment behaviour.
Fred
I want to assign a long int to an unsigned
short int. From what I've read, it will do
what I want, which is to assign as many of
the least significant bits as can fit.
Would I be right in assuming that the
LSBs are used regardless of whether the
sign is preserved?
Just for background, I am using a pair of
long ints returned by Posix's gettimeofday
to initialize erand48's 48-bit pseudorandom
generator. The context problem itself is
not one of ISO C, but the above behaviour
of assigning long to unsigned is (hopefully)
generic enough.
I suspect that the answer is that the bits
are treated as bits, signedness be damned,
and regardless of the numeric representation
(1 or 2's complement, or whatever else might
be out there). For my purposes, that's OK,
since the low order bits are still a good
random seed for when I initialize the
generator many times in quick succession.
I'm not using the standard "time" function
because I may initialize the generator
within 1 second of the last initialization.
Thanks for any confirmation or correction
of this assignment behaviour.
Fred