Hi,Im trying to convert numbers to a list of numbers representing it tothe base of something.An example.125 to the base 26 should return (4;21)Is there anything in q to handle this?
q){(floor x%y;x mod y)}[125;26]
4 21
Thanks Charles.That will only ever return 2 items?So say if the number was 1250 it returns 48 2 when Id like it toreturn a 3 int list here.It would be the same as converting a number to binary except the baseis 26 instead of 2.On Jan 7, 11:23?am, Charles Skelton <char…> wrote:> q){(floor x%y;x mod y)}[125;26]>> 4 21>> On Fri, Jan 7, 2011 at 10:36 AM, Daniel <cas…> wrote:> > Hi,>> > Im trying to convert numbers to a list of numbers representing it to> > the base of something.>> > An example.>> > 125 to the base 26 should return (4;21)>> > Is there anything in q to handle this?>> > –> >
Submitted via Google Groups</cas…></char…>
Does this work for you?
q){$[x<y;:x;:.z.s[floor x%y;y],(x mod y)]}[1250;26]
q)1 22 2
Pawan
Thats working perfect.Thanks for both your help!On Jan 7, 5:50?pm, pawan singh <pawan.sing…> wrote:> Does this work for you?>> q){$[x q)1 22 2>> Pawan>> On 7 January 2011 17:28, Daniel <cas…> wrote:>> > Thanks Charles.>> > That will only ever return 2 items?>> > So say if the number was 1250 it returns 48 2 when Id like it to> > return a 3 int list here.> > It would be the same as converting a number to binary except the base> > is 26 instead of 2.>> > On Jan 7, 11:23 am, Charles Skelton <char…> wrote:> > > q){(floor x%y;x mod y)}[125;26]>> > > 4 21>> > > On Fri, Jan 7, 2011 at 10:36 AM, Daniel <cas…> wrote:> > > > Hi,>> > > > Im trying to convert numbers to a list of numbers representing it to> > > > the base of something.>> > > > An example.>> > > > 125 to the base 26 should return (4;21)>> > > > Is there anything in q to handle this?>> > > > –> > > > You received this message because you are subscribed to the Google> > Groups> > > > “Kdb+ Personal Developers” group.> > > > To post to this group, send email to personal-kdbplus@googlegroups.com> > .> > > > To unsubscribe from this group, send email to> > > > personal-kdbplus+unsubscribe@googlegroups.com> > >> > > > .> > > > For more options, visit this group at> > > >http://groups.google.com/group/personal-kdbplus?hl=en.>> > –> >
Submitted via Google Groups</cas…></char…></cas…></pawan.sing…>
On Jan 7, 4:36?am, Daniel <cas…> wrote:> Im trying to convert numbers to a list of numbers representing it to the base of something.>> An example.>> 125 to the base 26 should return (4;21)>> Is there anything in q to handle this?in theory vs does this, but it’s only implemented for 16 afaikq)16 vs 1257 13k){x:y}'nyi@26:125q.q))note that sv performs the opposite operation, polynomial evaluation,and is implemented for all x’s (and can thus be used to test anysolution to your problem)q)16 sv 7 13125q)26 sv 4 21125you can solve it either with your own recursionq)base:{$[x=y)#(i:first x)div y),x mod y}[;y])over x}q)base[125]264 21</cas…>