English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i m doing some calculation program with fixed point in c++ so its involving bit shift.

(1) a = b + c >> 1

(2) a = b + (c>>1)

i think bit shift in (1) is different with (2), is it true? and could this different effect the calculation result much?

2007-02-22 18:49:43 · 1 answers · asked by astri 2 in Science & Mathematics Engineering

1 answers

Whether the bit shift unitary operator has higher precedent than the addition binary operator may be compiler dependent.

If your compiler gave the bit shift operator a precedence NOT higher than what it gave the addition operator, that is everything on both statements are to be done from left to right, the result in (1) would be one half of b less than result in (2). Written in equivalent forms: (1) a = (b + c) / 2; whereas (2) a = b + (c / 2)

2007-02-22 20:15:11 · answer #1 · answered by sciquest 4 · 0 0

fedest.com, questions and answers