Christian
Christian

Reputation: 1628

C# UL and >> operators

What does this meaning mean in words?

(SomeVariable * 330UL >> 10)

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

Upvotes: 1

Views: 397

Answers (4)

Hans Passant
Hans Passant

Reputation: 941635

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;

Upvotes: 2

Mark Hurd
Mark Hurd

Reputation: 10931

SomeVariable times 330 as an unsigned long shift right 10 bits

Upvotes: 1

Andrey
Andrey

Reputation: 60065

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

Upvotes: 1

Pavel Radzivilovsky
Pavel Radzivilovsky

Reputation: 19114

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).

Upvotes: 5

Related Questions