two's complement - what if there's one more bit needed to represent a binary in 2's complement form -


i’m doing computer science a-level course in high school , working on two’s complement arithmetic. reason don’t quite it. know how convert signed integer two’s complement equivalent, here’re confusions:

  1. i’ve done research , people op-code carry-bit tells cpu if 2’s complement code represents positive integer or negative, carry-bit ignored according people; instance, adding 1111 (-1) 1000 (-8) 10111 (-9), if it’s 4-bit computer, significant bit 5th bit cannot stored, how computer deal ?
  2. a trivial question if it’s given 00110011 represent signed integer in two’s complement form, how know if actual code 0110011, positive number (in 2’s complement form), or 110011, negative number (in 2’s complement form) ?

thanks!

typically, doesn't fit lost. so, 11112 + 10002 = 01112. however, cpus have special flags set 0 or 1 depending on whether or not there's unsigned overflow (the carry flag) , signed overflow (the overflow flag). cpus may able automatically raise overflow exception when arithmetic instruction can't produce result without overflow.

typically, cpu not care if 11112 -110 or 1510. binary addition , subtraction of 2 n-bit integers gives same n-bit sum or difference irrespective of whether you're operating on unsigned integers or 2's complement signed integers. same true when multiplying 2 n-bit signed 2's complement or unsigned integers: n least significant bits of product same in both cases.

iow, it's job keep track of types you're manipulating, take care of overflows (if they're possible) , select proper instructions types (e.g. typically have signed , unsigned division, signed , unsigned comparison, etc).


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -