I average two 8-bit samples with assign avg = (a + b) >> 1; where all three are [7:0]. For a = 200 and b = 100 I get 22 instead of 150. Yet assign sum = a + b; with a 9-bit sum gives the correct 300. In another module a signed 8-bit value of -1 added to an unsigned 8-bit value of 1 and stored in a 16-bit signed result gives 256 instead of 0.
How does Verilog decide the width and signedness of an expression, and how should I write these two calculations?




