R
robert.h.lowe
Hi,
I'm looking for a computationally fast means of XOR folding
the individual bytes of an unsigned 32-bit int, and an unsigned
16-bit int. Can I point a char * at the address of each of
the int's (in succession), and safely access each byte?
Danger, danger, Will Robinsin!?? Any better ideas?? I'm
assuming this is faster than a series of 8-bit right shifts
followed by ORs with 255 as input to the XOR. E.g.
int i;
char *base;
uint32_t y = <blah>;
uint8_t x = 0;
base = (char *) &y;
for (i=0; i<4; i++) {
x ^= *(base+i);
}
(yes, differences in endianess will result in different byte ordering,
which might be important if only certain bytes were to be factored
into the result.)
versus
int i;
uint32_t y = <blah>;
uint8_t x = 0;
for (i=0; i<4; i++) {
x ^= ((t >> (8*i)) | 255); /* or some destructive variant for t */
/* ...to avoid the multiplication
*/
}
Also, should this result in too many collisions (as a hash key),
widening the space will have to result in shifts, e.g. 9 or 10-bits
plus a small number of bits left over... perhaps just better to do
it that way to begin with?
TIA,
Robert
I'm looking for a computationally fast means of XOR folding
the individual bytes of an unsigned 32-bit int, and an unsigned
16-bit int. Can I point a char * at the address of each of
the int's (in succession), and safely access each byte?
Danger, danger, Will Robinsin!?? Any better ideas?? I'm
assuming this is faster than a series of 8-bit right shifts
followed by ORs with 255 as input to the XOR. E.g.
int i;
char *base;
uint32_t y = <blah>;
uint8_t x = 0;
base = (char *) &y;
for (i=0; i<4; i++) {
x ^= *(base+i);
}
(yes, differences in endianess will result in different byte ordering,
which might be important if only certain bytes were to be factored
into the result.)
versus
int i;
uint32_t y = <blah>;
uint8_t x = 0;
for (i=0; i<4; i++) {
x ^= ((t >> (8*i)) | 255); /* or some destructive variant for t */
/* ...to avoid the multiplication
*/
}
Also, should this result in too many collisions (as a hash key),
widening the space will have to result in shifts, e.g. 9 or 10-bits
plus a small number of bits left over... perhaps just better to do
it that way to begin with?
TIA,
Robert