Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!iconsys.icon.com!mday From: mday@iconsys.icon.com (Matthew T. Day) Newsgroups: comp.lang.c Subject: Re: C to Pascal Message-ID: <6@iconsys.icon.com> Date: 6 Feb 90 21:06:25 GMT References: <1648@milton.acs.washington.edu> Organization: Sanyo/Icon International, Orem, Utah Lines: 36 From article <1648@milton.acs.washington.edu>, by pingpong@milton.acs.washington.edu (jimmy): > Does anyone know how to convert the following C code to Pascal code: > > int compute_num(char *word) > { > int num=0; > while (*word) > num = (num << 5) + *word++; > return num; > } How about (just a guess, nothing tested): type str255 = string[255]; function compute_num(word : str255) : integer; var num, len, x : integer; begin num := 0; x := 1; len := length(word); while (x <= len) do begin num := (num shl 5) + ord(word[x]); x := x + 1; end; compute_num := num; end; The "shl" operator is available in Turbo Pascal, maybe other Pascal compilers don't call their shift-left operator "shl", but they should have something. -- +-------------------------------------------------------+ | Matthew T. Day, Sanyo/Icon International, Orem, UT | | E-mail: mday@iconsys.icon.com (..!uunet!iconsys!mday) | +-------------------------------------------------------+