From: "Pavel Cisar" 22.10.1999 13:29 Hi, Here you are rotines for compress/decompress GUIDs (mentioned by Grant). They're part of Nexus core library :o) {** Function return highly compressed string representation of GUID. This string is only 26 characters long and contain uppercase letters and numbers. For opposite conversion see } function NxPackGUID (AGUID : TGUID) : string; var A : packed array [0..16] of byte absolute AGUID; I, P, N : integer; begin Result := ''; P := 0; for I := 0 to 25 do begin N := 0; case (I mod 8) of 0 : N := (A [P] and $F8) shr 3; 1 : begin N := ((A [P] and $07) shl 2) or ((A [succ (P)] and $C0) shr 6); inc (P); end; 2 : N := ((A [P] and $3E) shr 1); 3 : begin N := ((A [P] and $01) shl 4) or ((A [succ (P)] and $F0) shr 4); inc (P); end; 4 : begin N := ((A [P] and $0F) shl 1) or ((A [succ (P)] and $80) shr 7); inc (P); end; 5 : N := ((A [P] and $7C) shr 2); 6 : begin N := ((A [P] and $03) shl 3) or ((A [succ (P)] and $E0) shr 5); inc (P); end; 7 : begin N := (A [P] and $1F); inc (P); end; end; if N > 5 then Result := Result + chr (N - 6 + ord ('A')) else Result := Result + chr (N + ord ('0')); end; end; {** Converts string representation of GUID to binary form. Converts standard or packed string representation returned by function to standard 128-bit GUID.} function NxUnPackGUID (AGUIDStr : string) : TGUID; var A : packed array [0..16] of byte; I, P, N : integer; begin if Copy (AGUIDStr, 1, 1) = '{' then Result := StringToGUID (AGUIDStr) else begin FillChar (A, sizeof (A), 0); if Length (AGUIDStr) = 26 then begin P := 0; for I := 0 to 25 do begin N := ord (AGUIDStr [succ (I)]); if N >= ord ('A') then N := N - ord ('A') + 6 else N := N - ord ('0'); case (I mod 8) of 0 : A [P] := (N and $1F) shl 3; 1 : begin A [P] := A [P] or ((N shr 2) and $07); inc (P); A [P] := (N shl 6) and $C0; end; 2 : A [P] := A [P] or ((N shl 1) and $3E); 3 : begin A [P] := A [P] or ((N shr 4) and $01); inc (P); A [P] := (N shl 4) and $F0; end; 4 : begin A [P] := A [P] or ((N shr 1) and $0F); inc (P); A [P] := (N shl 7) and $80; end; 5 : A [P] := A [P] or ((N shl 2) and $7C); 6 : begin A [P] := A [P] or ((N shr 3) and $03); inc (P); A [P] := ((N shl 5) and $E0); end; 7 : begin A [P] := A [P] or (N and $1F); inc (P); end; end; end; move (A, Result, sizeof (Result)); end else Result := NxNullGuid; end; end; Pavel Cisar Delphree.org CEO http://delphree.clexpert.com Nexus project coordinator http://delphree.clexpert.com/pages/projects/nexus/default.htm From: Grant Dickinson > Storage is cheap, but if you are still concerned, here are a couple of > tricks: > > 1 GUID = 32 Hex Digits = 16 bytes = 128 bits. However, to represent it as a > string, you would need 36 Chars i.e CHAR(36). > This can be improved by removing the dashes, which would mean you'd need > only 32 Chars, i.e. CHAR(32). > This can be improved again by converting the value to Base32 (0..9, A..Z > sans I, O, S, Z). It (theoretically, if my maths is correct) should then > come down to 26 Chars, i.e. CHAR(26). There are standard algorithms to do > this. > > So you're down to 26/36, approx 7/10 of the storage reqs already. ************************************************************************ * This message came from the list servers at http://www.mers.com * * To remove yourself from the list: send an email to listproc@mers.com * * in the body of the message put: unsubscribe INTERBASE * * InterBase Search Engine http://www.mers.com/searchsite.html * * InterBase FAQ http://www.mers.com/faqinterbase.html * ************************************************************************