c - signed two's complement arithmetic -


i thinking on data types ranges, question arises. know signed char's range -128 127. got how 127 comes, i.e. 0111111 = +127

but not how -128 comes? if on sign bit 11111111, how equal -128 ?

most of time, computers use what's called 2's complement represent signed integers.

the way 2's complement works possible values in huge loop, 0, max_value, min_value, zero, , on.

so minimum value maximum value +1 - 01111111 = 127, , 10000000 = -128.

this has nice property of behaving same unsigned arithmetic - if want -2 + 1, have 11111110 + 00000001 = 11111111 = -1, using same hardware unsigned addition.

the reason there's value on low end choose have numbers high-bit set negative, means 0 takes value away positive side.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -