From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 6 Aug 2010 19:43:28 +0400 From: Sergey Vlasov To: devel@lists.altlinux.org Message-ID: <20100806154328.GA6231@atlas.home> Mail-Followup-To: devel@lists.altlinux.org References: <20100804211817.GB10145@altlinux.org> <20100804212620.GA28494@wo.int.altlinux.org> <20100804213812.GC10145@altlinux.org> <20100804220513.GA9825@wo.int.altlinux.org> <20100805074140.GD10145@altlinux.org> <20100806131719.GB10200@altlinux.org> <20100806142638.GC10200@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="liOOAslEiF7prFVr" Content-Disposition: inline In-Reply-To: <20100806142638.GC10200@altlinux.org> Subject: Re: [devel] base2 <-> base62 X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Aug 2010 15:43:29 -0000 Archived-At: List-Archive: List-Post: --liOOAslEiF7prFVr Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 06, 2010 at 06:26:38PM +0400, Alexey Tourbin wrote: > On Fri, Aug 06, 2010 at 05:17:19PM +0400, Alexey Tourbin wrote: > > =EE=CF =D3 =D0=C5=D2=D7=CF=C7=CF =D2=C1=DA=C1 =D5 =CD=C5=CE=D1 =CF=D0= =D1=D4=D8 =CE=C5 =D0=CF=CC=D5=DE=C9=CC=CF=D3=D8 =CE=C1=D0=C9=D3=C1=D4=D8 = =C4=C5=CB=CF=C4=C9=D2=CF=D7=C1=CE=C9=C5. > > =EB=D4=CF =C8=CF=DE=C5=D4 =CD=CE=C5 =D0=CF=CD=CF=DE=D8? =F7=CF=D4 =D0= =CF=CC=CE=CF=D3=D4=D8=C0 =CB=CF=C4=C9=D2=CF=D7=C1=CE=C9=C5. =F0=CF=D3=CC= =C5 =C4=C5=CB=CF=C4=C9=D2=CF=D7=C1=CE=C9=D1 > > =D2=C1=DA=D2=C5=DB=C1=C5=D4=D3=D1, =DE=D4=CF=C2=D9 =CD=C1=D3=D3=C9=D7 b= itv[] =D3=CF=C4=C5=D2=D6=C1=CC =D7 =CB=CF=CE=C3=C5 =CE=C5=D3=CB=CF=CC=D8=CB= =CF =CC=C9=DB=CE=C9=C8 > > =CE=D5=CC=C5=CA. > >=20 > > const char *bitv_to_base62(int bitc, char bitv[]) > > { > > int base62c =3D 0; > > char *base62v =3D NULL; > > void put_char(int c) > > { > > int realloc_delta =3D 1024; > > if ((base62c & (realloc_delta - 1)) =3D=3D 0) > > base62v =3D realloc(base62v, sizeof(*base62v) * (base62c + realloc_de= lta)); > > base62v[base62c++] =3D c; > > } > > void put_digit(int c) > > { > > if (c < 10) > > put_char(c + '0'); > > else if (c < 36) > > put_char(c - 10 + 'a'); > > else if (c < 62) > > put_char(c - 36 + 'A'); > > } > > int i; > > int bits6 =3D 0; > > int num6b =3D 0; > > for (i =3D 0; i < bitc; i++) { > > if (bits6 < 6) > > num6b |=3D bitv[i] << bits6++; > > if (bits6 =3D=3D 6) { > > switch (num6b) { > > case 61: > > put_digit(61); > > // extra "0" binary bit > > bits6 =3D 1; > > num6b =3D 0; > > break; > > case 62: > > put_digit(61); > > // extra "10" binary bits > > bits6 =3D 2; > > num6b =3D 1; > > break; > > case 63: > > put_digit(61); > > // extra "11" binary bits > > bits6 =3D 2; > > num6b =3D 3; > > break; > > default: > > assert(num6b < 61); > > put_digit(num6b); > > bits6 =3D 0; > > num6b =3D 0; > > break; > > } > > } > > } > > if (bits6) { > > assert(num6b < 61); > > put_digit(num6b); > > } > > put_char(0); > > return base62v; > > } >=20 > =EE=D5=D6=CE=CF =D5=DE=C9=D4=D9=D7=C1=D4=D8, =DE=D4=CF =DA=CE=C1=DE=C5=CE= =C9=C5 61 (Z) =CD=CF=D6=C5=D4 =C9=C4=D4=C9 =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=CE=C1=C4=CF =CB=CC=C1=D3=D4=D8 > Z =D7 =D3=D4=C5=CB =C9 =D2=C1=D3=D0=C1=CB=CF=D7=D9=D7=C1=D4=D8 =D7 =CF=C2= =D2=C1=D4=CE=CF=CD =D0=CF=D2=D1=C4=CB=C5. =FC=D4=CF =D3=CC=C9=DB=CB=CF=CD = =D3=CC=CF=D6=CE=CF. > =F2=C1=D3=D0=C1=CB=CF=D7=CB=C1 =C4=CF=CC=D6=CE=C1 =D2=C1=C2=CF=D4=C1=D4= =D8 =C2=D9=D3=D4=D2=CF =C9 =C2=D9=D4=D8 =C2=CF=CC=C5=C5-=CD=C5=CE=C5=C5 =D4= =D2=C9=D7=C9=C1=CC=D8=CE=CF=CA. > =F4=CF=C7=C4=C1 =CD=CF=D6=CE=CF =D0=CF=D0=D9=D4=C1=D4=D8=D3=D1 =D3=C4=C5= =CC=C1=D4=D8 =D4=C1=CB, =DE=D4=CF=C2=D9 =D0=CF=D3=CC=C5 =D0=C5=D2=D7=CF=C7= =CF Z =CE=C9=CB=CF=C7=C4=C1 > =CE=C5 =CD=CF=C7=CC=CF =C9=C4=D4=C9 =D7=D4=CF=D2=CF=C5 Z. >=20 > char bitv[] =3D { > 1, 0, 1, 1, 1, 1, > 1, 1, 1, 1, 1, 0, > }; --liOOAslEiF7prFVr Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkxcLaAACgkQW82GfkQfsqIEjQCfS/JSgNBQD5sSAixaWd8bZDPd RvsAoIxx0GFaZWtybJMoAzjF71j4IP+B =rei3 -----END PGP SIGNATURE----- --liOOAslEiF7prFVr--