64bit - C circular shift 64 bit not working properly

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m trying to apply a circular bitshift of n bits (varies between 1 and 62) using the << and the >> operators but the result is not coming out as expected...

It works well with circular shifts of 1 but not more (I haven t verified all of them)...

uint64_t array[25];
for(i=0;...)
   array[i] = ((s[n] << n) | (s[i] >> (64-n)));

Example:

   ---> Trying to shift this: 00:00:02:26:00:00:00:2D
   ---> I got this:           00:80:80:09:00:00:40:0B

Which doesn t make any sense because I m not even being able to understand what happened.

Any help would be appreciated. I am trying to do this on a 32 bit machine... maybe it has something to do with that...

Thanks a lot ;)

Answers

use s[i] instead of s[n]:

uint64_t array[25];
for(i=0;...)
   array[i] = ((s[i] << n) | (s[i] >> (64-n)));

You are mixing together the index variable i and the shift span n which makes little sense in this context. I m assuming that s is:

uint64_t s[25];

And no, it s not an architecture issue... uint64_t is an unsigned 64 bit integer both in x86 and ia64 families. In the latter 64bit integers are handled natively by the CPU, in the former you have to use more registers to do the same things...

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/22765448/c-circular-shift-64-bit-not-working-properly

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils