Re: A83: Re: I am new
[Prev][Next][Index][Thread]
Re: A83: Re: I am new
Alan C Johnson wrote:
>
> >Smiths wrote:
> >>
> >> How do you give a number a negative??
> >
> >You can interpret a byte or word however you want. What you have
> >stored
> >in memory is not a number; it's just a series of bits. The context
> >will
> >tell you whether or not the number is signed - usually negative
> >numbers
> >are indicated with the left most bit set. I believe the Z80/ROM uses
>
> Then if -7=249, -7=%11111001, but your sying -7 should equal %10000111
> which is 135. I don't understand
No, two's complement doesn't work like that (sign magnitude is a
representation where setting the sign bit is like multiplying by -1).
Instead, the values wrap around.
0000 = 0
0001 = +1
0010 = +2
0011 = +3
0100 = +4
0101 = +5
0110 = +6
0111 = +7
1000 = -8
1001 = -7
1010 = -6
1011 = -5
1100 = -4
1101 = -3
1110 = -2
1111 = -1
That is, the values wrap from the maximum positive value to the minimum
negative value. There is one more possible negative value than positive
(-8 to 7 here), since 0 is represented as a positive number.
--
John Kugelman. kugelman@mnsinc.com
I believe we can change anything.
I believe in my dream.
- Joe Satriani
References: