tags:

views:

93

answers:

4

Hi!

What does this meaning mean in words?

(SomeVariable * 330UL >> 10)

Is it: SomeVariable times 3.3 shift right 10 bit??

Kind regards!

+5  A: 

No.

It means SomeVariable times 330, promote to long and shift non-cyclically right 10bits.

(it would be cyclic, or arithmetic shift without the promotion).

Pavel Radzivilovsky
@Pavel Radzivilovsky > The UL promotes the 330 and not the result, right? The result will be long or `SomeVariable`'s type, whichever is more precise. Why isn't it cyclic? I don't understand this, is it: because of the datatype; because it is defined in the language that promoted types don't shift cyclically; something else?
ANeves
330UL is not promotion, it is just the type of the literal. Promotion is due to the type of the argument 330UL. This, makes the result unsigned, and the unsigned operand of >> makes it a non-arithmetic shift.
Pavel Radzivilovsky
+1  A: 

UL stands for Unsigned Long. >> yes it is bitwise arithmetic shift.

Andrey
+1  A: 

SomeVariable times 330 as an unsigned long shift right 10 bits

Mark Hurd
+2  A: 

Right-shifting an integral value by one is equivalent to dividing it by 2. Two shifts equivalent to dividing by 4. Etcetera. Which makes the expression equivalent to:

ulong value = ((ulong)SomeVariable * 330) / 1024;
Hans Passant