avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] AVR-libc-dev Digest, Vol 103, Issue 1


From: Bradley Jarvis
Subject: Re: [avr-libc-dev] AVR-libc-dev Digest, Vol 103, Issue 1
Date: Fri, 17 Jun 2011 13:03:58 +1000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110317 Lightning/1.0b2 Thunderbird/3.1.9

Hi Dmitry
Does this modification of your algorithm still actually work? I just
tweeked your code by removing the 'first' variable and use the index j
to perform the same check, this should still make sure that the first
number is non-zero before filling with zeros, just have to make sure
that pgm_read_byte(letters+k)='0' when k=0 which is your algorithm I
don't think uses due to the  if (check > val) statement.

for (i = j = 0; i < max; i++) {
  unsigned long check = pgm_read_dword(d + i);
  k = 0;
  while(check <= __val) {
    __val -= check;
    k++;
  }
  if (k||j) __s[j++] = pgm_read_byte(letters + k);
}

if (!j) __s[j++] = '0';
__s[j] = 0;

return __s;

Depending on what i is the following variant may also help speed/size

where max=d+max;
for (i = d, j = 0; i < max; i++) {
  unsigned long check = pgm_read_dword(d);


I have compiled the two algorithms and the variant is quite a bit
smaller, I have not tested that it gives correct output.

Regards Brad

On 06/17/11 02:00, address@hidden wrote:
>         for (i = j = 0, first = 1; i < max; i++) {
>                 unsigned long check = pgm_read_dword(d + i);
>                 if (check > __val) {
>                         if (first)
>                                 continue;
>                         __s[j++] = '0';
>                         continue;
>                 }
>                 first = k = 0;
>                 while(check <= __val) {
>                         __val -= check;
>                         k++;
>                 }
>
>                 __s[j++] = pgm_read_byte(letters + k);
>         }
>
>         if (first)
>                 __s[j++] = '0';
>         __s[j] = 0;
>
>         return __s;


-- 
Bradley Jarvis

Pocket Innovations
Phone: (03) 5622-1773
Mobile: 0439 988-337





reply via email to

[Prev in Thread] Current Thread [Next in Thread]