For two's complement to work, you need the leading bit to be 0 for non-negative numbers.
Limiting the range of considered numbers (as you would for a fixed width bit sequence) is one tool you can use here. This can also be looked at as a padding issue (and the rude treatment #:'s results get from frame fill can be motivating, for treating this issue properly). -- Raul On Wed, Dec 14, 2011 at 11:02 AM, Devon McCormick <devon...@gmail.com> wrote: > The "embarassing" example happens because the full scope of "two's > complement" notation implies fixed-width binary numbers, not the > variable-width version given in this thread. > > On Wed, Dec 14, 2011 at 10:41 AM, Kip Murray <k...@math.uh.edu> wrote: > >> On 12/14/2011 6:07 AM, Linda Alvord wrote: >> > I really don't think that you can ever write a program good enough that >> the >> > the number 8 in binary is _8 in decimals >> > >> > hcinv 1 0 0 0 >> > _8 >> >> THAT /IS/ EMBARRASSING ! >> >> > I have lived my mathematical life without being able to write negative >> > binary numbers. I have always ignored two's complements as beyond my >> scope >> > of interest. It is like saying there are no negative numbers. It will >> be >> > ok if 13 stands for _13 and we'll all be happy. >> > >> > I'm sure that much of the world deals well without imaginary numbers. >> > However, they must have been a mess to develop so they work flawlessly. >> > Note that they do have a strange appearance but if you understand them >> you >> > get used to them. >> > >> > In my world, if I want _8 I write _1 0 0 0 which is in the 8 4 2 >> 1 >> > 8's digit. So what is _14 ? >> > >> > Linda >> >> IN YOUR WORLD _14 IS >> >> - 1 1 1 0 >> _1 _1 _1 0 >> >> AND IN TWO'S-COMPLEMENT IT IS >> >> tcng 0 1 1 1 0 >> 1 0 0 1 0 >> >> ------------------ >> >> stack =: ,.&.|: NB. stack x over y >> >> hv =: (0 {:: <"1) :: ] NB. return head vector >> >> Tbln =: 2 2 2 $ 0 0,1 1,1 1,0 1 NB. table for tcng, see opn >> >> ban =: 0 ,~ 0 ,.~ 0 ,.~ ] NB. build argument, see tcng >> >> opn =: ] stack~ (0 { [) , Tbln {~ [: < (0 { [) ,~ 2 { [: hv ] >> >> tcng =: (1 {"1 [: }: [: opn/ ban)"1 NB. TWO'S-COMPLEMENT NEGATIVE >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > > > > -- > Devon McCormick, CFA > ^me^ at acm. > org is my > preferred e-mail > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm