Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Shifting unsigned long long values by 64 bits

Reply
Thread Tools

Shifting unsigned long long values by 64 bits

 
 
Kenneth Brody
Guest
Posts: n/a
 
      01-23-2007
"christian.bau" wrote:
>
> David T. Ashley wrote:
>
> > Wow! I've never seen this behavior. I would have assumed that shifting
> > something too many times to the left always gets you zero and to the right
> > either gets you zero or -1.

>
> On IA-32 processors (Pentium, Athlon etc. ), a hardware shift
> instruction uses only the lower five bit of the shift count, so (x <<
> n) produces the same result whether n == 32 or n == 0.


If it used all 32 bits of the "shift by" value, imagine how long
a 4 billion bit shift would take.

(The only other option being to check that the value had non-zero
bits in the upper part, and force zero/negative-one as the result
immediately. However, as long as it's documented, the current
behavior of only using the low 5 bits makes sense from both a
hardware and software point of view.)

Getting back to C, this is probably the exact reason why shifts of
larger than the value is undefined. (Though "implementation
defined" may have been more appropriate, I suppose there may be
hardware in which the results are undefined at the hardware level.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <private.php?do=newpm&u=>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shifting bits, shift 32 bits on 32 bit int GGG C++ 10 07-06-2006 06:09 AM
extracting front bits from an unsigned long long? Digital Puer C Programming 36 11-13-2005 12:05 PM
what about unsigned and signed 8 bits number, 16 bits, etc?? sarmin kho Python 2 06-15-2004 06:40 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57