Wow! brAai 345454 _447567 1 0 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 0 _1 _1 0 _1 _1 0 _1 0 _1 0 0 0 _1 0 0 _1 _1 _1 _1 #. 1 0 1 0 1 0 0 0 1 0 1 0 1 1 0 1 1 1 0 345454 #._1 _1 0 _1 _1 0 _1 0 _1 0 0 0 _1 0 0 _1 _1 _1 _1 _447567 This is beautiful: a=: brAai _49 a _1 _1 0 0 0 _1 %:a 0j1 0j1 0 0 0 0j1 *:%:a _1 _1 0 0 0 _1
However, #. Will need some modification: #.0j1 0j1 0 0 0 0j1 0j49 *:0j49 _2401 Linda -----Original Message----- From: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] On Behalf Of Kip Murray Sent: Wednesday, December 28, 2011 2:48 PM To: Programming forum Subject: Re: [Jprogramming] Binary representation without #: or #. Very instructive code. Using results of Aai, I would "bludgeon" add as follows: brAai =: (**|.@:(2| [:}:<.@-:^:a: )&.|:@:|)`,@.(0-:]) NB. binary rep briAai=: (++:)/&|. "1 NB. Also by Aai, inverse of binary representation add =: ([: brAai +&briAai)"1 brAai 7 _3 NB. binary reps for 7 and _3 1 1 1 0 _1 _1 1 1 1 add 0 _1 _1 NB. 7 + _3 is 4 1 0 0 (If you made brAai the obverse of briAai you could do add =: +&.briAai ) Kip On 12/27/2011 7:10 PM, Björn Helgason wrote: > add=: 4 : 0 > smoutput '' > CARRY=: 0 > a=.|.2^i.#x > b=.+/a*x > c=.+/a*y > smoutput 'x + y = ',(": b),' + ',(": c),' = ',": b+c > smoutput '' > d=.|.CARRY,~> (|.x) addbin&.> |.y > e=.|.2^i.#d > smoutput ' ',":a > smoutput 'x is : ',":x > smoutput 'y is : ',":y > smoutput '' > smoutput ' ',":e > smoutput 'x + y is : ',(": d), ' = ', ": +/ d * e > smoutput '' > ) > > > > addbin=: 4 : 0 > a=.x+y + CARRY > select. a > case. 0 do. CARRY=: 0 > 0 > case. 1 do. CARRY=: 0 > 1 > case. 2 do. CARRY=: 1 > 0 > case. 3 do. CARRY=: 1 > 1 > end. > ) > > > > 0 1 1 add 1 1 1 > > x + y = 3 + 7 = 10 > > 4 2 1 > x is : 0 1 1 > y is : 1 1 1 > > 8 4 2 1 > x + y is : 1 0 1 0 = 10 > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm