Example CODICE32.PRT
; CODICE32
;
; Program for Proteus
;
; (C) 2003-2004 Simone Zanella Productions
;
; Functions for encoding/decoding Code 32 (Italian Pharmaceutical).

FUNCTION Conv32(cod)

; Alphabet for Code 32 calculation
base32 = "0123456789BCDFGHJKLMNPQRSTUVWXYZ"

; Calculate check digit
c = C32CheckDigit(cod)
d = ""
; Transform number into the alphanumeric string 
; corresponding to Code 32 representation
FOR x = 1 TO 6
  d = SUBSTR(base32, INC(MOD(c, 32)), 1) d
  DIV(@c, 32)
NEXT
; Return new code
RETURN d


FUNCTION C32CheckDigit(cod)

; Calculate check digit on cod, return the string with the added check digit

p = 0
FOR x = 2 TO 8 STEP 2
  c = MUL(SUBSTR(cod, x, 1), 2)
  ADD(@p, DIV(c, 10), MOD(c, 10))
NEXT
FOR x = 1 TO 7 STEP 2
  ADD(@p, SUBSTR(cod, x, 1))
NEXT
RETURN cod MOD(p, 10)


FUNCTION ReConv32(cod)

; Return the numeric code corresponding to cod (Code 32)

; Alphabet for Code 32 calculation
base32 = "0123456789BCDFGHJKLMNPQRSTUVWXYZ"

c = 0
FOR x = 1 TO 6
  d = SUBSTR(cod, x, 1)
  p = STRSTR(base32, d)
  c = ADD(MUL(c, 32), DEC(p))
NEXT
RETURN PADL(c, 9, "0")


CONSOLELN "02608901" ", " Conv32("02608901") ", " ReConv32(Conv32("02608901"))
CONSOLELN "12358231" ", " Conv32("12358231") ", " ReConv32(Conv32("12358231"))
CONSOLELN "44812722" ", " Conv32("44812722") ", " ReConv32(Conv32("44812722"))
CONSOLELN "12456762" ", " Conv32("12456762") ", " ReConv32(Conv32("12456762"))
CONSOLELN "12345678" ", " Conv32("12345678") ", " ReConv32(Conv32("12345678"))
CONSOLELN "90206826" ", " Conv32("90206826") ", " ReConv32(Conv32("90206826"))

ABORT 0

Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell