Click here to Skip to main content
15,907,396 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: sscanf: parsing a file Pin
Tim Craig26-Mar-10 8:28
Tim Craig26-Mar-10 8:28 
AnswerRe: sscanf: parsing a file Pin
Iain Clarke, Warrior Programmer26-Mar-10 4:37
Iain Clarke, Warrior Programmer26-Mar-10 4:37 
GeneralRe: sscanf: parsing a file Pin
CPallini26-Mar-10 9:25
mveCPallini26-Mar-10 9:25 
GeneralRe: sscanf: parsing a file Pin
Tim Craig26-Mar-10 18:21
Tim Craig26-Mar-10 18:21 
GeneralRe: sscanf: parsing a file Pin
CPallini27-Mar-10 5:30
mveCPallini27-Mar-10 5:30 
GeneralRe: sscanf: parsing a file Pin
Tim Craig27-Mar-10 8:13
Tim Craig27-Mar-10 8:13 
AnswerRe: sscanf: parsing a file Pin
David Crow26-Mar-10 4:47
David Crow26-Mar-10 4:47 
QuestionAdler32 Algorithm Doubts Pin
rupeshkp72825-Mar-10 23:42
rupeshkp72825-Mar-10 23:42 
I am writing a adler32 code to compute the adler32 checksum of a string.
On the net I came across various sample codes:
I did not understand some code entirely as <b>it has additional code</b> marked in bold below apart from the basic implementation of the adler32 logic.
I did not understand the addional part as to what is is doing.
Can anybody experienced with adler32 give some hint on it?

The various sample codes are:

//---------------------------------------------------------------------
// WIKI
I understood this code as its the basic implementation of the adler32 logic.
So no doubts in this.

/* Loop over each byte of data, in order */
for (size_t index = 0; index < blen; ++index)
{
a = (a + buff[index]) % BASE;
b = (b + a) % BASE;
}

wweak_cs = (b << 16) | a;
//---------------------------------------------------------------------
// RSYNC
I did not understand some code marked in bold below.
{
#define CHAR_OFFSET 0
char *buf = buff;
int len = blen;
int index = 0;
UINT32 s1, s2;

s1 = s2 = 0;
for (index = 0; index < (len-4); index+=4)
{
s2 += 4*(s1 + buf[index]) + 3*buf[index+1] + 2*buf[index+2] + buf[index+3] + 10*CHAR_OFFSET;
s1 += (buf[index+0] + buf[index+1] + buf[index+2] + buf[index+3] + 4*CHAR_OFFSET);
}

for (; index < len; index++)
{
s1 += (buf[index]+CHAR_OFFSET); s2 += s1;
}
rweak_cs = (s1 & 0xffff) + (s2 << 16);
weak_cs = rweak_cs;
}
//---------------------------------------------------------------------
// sharpdevelop
I did not understand some code marked in bold below.

{
char *buf = buff;
int len = blen;
sweak_cs = 1;
int s1 = sweak_cs & 0xFFFF;
int s2 = sweak_cs >> 16 & 0xFFFF;
int index =0;

while (len > 0)
{
int n = 3800;
if (n > len)
{
n = len;
}
len -= n;

while (--n >= 0)
{
s1 = s1 + (int)(buf[index++] & 0xFF);
s2 = s2 + s1;
}
s1 %= BASE;
s2 %= BASE;
}

sweak_cs = (s2 << 16) | s1;
weak_cs = sweak_cs;
}
//---------------------------------------------------------------------
//altivec
I did not understand some code marked in bold below.

{
#define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);

# define MOD(a) a %= BASE

char *buf = buff;
int len = blen;
aweak_cs = 1;
unsigned long s1 = aweak_cs & 0xffff;
unsigned long s2 = (aweak_cs >> 16) & 0xffff;
int k;
while (len > 0)
{
k = len < NMAX ? (int)len : NMAX;
len -= k;
while (k >= 16)
{
DO16(buf);
buf += 16;
k -= 16;
}

if (k != 0)
{
do
{
s1 += *buf++;
s2 += s1;
} while (--k);
}
MOD(s1);
MOD(s2);
}

aweak_cs = (s2 << 16) | s1;
weak_cs = aweak_cs;
}

Can anybody clear the doubts?
QuestionRe: Adler32 Algorithm Doubts Pin
CPallini26-Mar-10 1:09
mveCPallini26-Mar-10 1:09 
AnswerRe: Adler32 Algorithm Doubts Pin
tom groezer26-Mar-10 1:38
tom groezer26-Mar-10 1:38 
GeneralRe: Adler32 Algorithm Doubts Pin
CPallini26-Mar-10 1:44
mveCPallini26-Mar-10 1:44 
AnswerRe: Adler32 Algorithm Doubts Pin
rupeshkp72828-Mar-10 19:19
rupeshkp72828-Mar-10 19:19 
QuestionWxWidgets question about wxFileSystem and wxFSFile Pin
brdavid25-Mar-10 21:28
brdavid25-Mar-10 21:28 
AnswerRe: WxWidgets question about wxFileSystem and wxFSFile Pin
Stuart Dootson25-Mar-10 21:54
professionalStuart Dootson25-Mar-10 21:54 
GeneralRe: WxWidgets question about wxFileSystem and wxFSFile Pin
brdavid26-Mar-10 0:26
brdavid26-Mar-10 0:26 
Questionlocalization issue Pin
Member 59031025-Mar-10 21:27
Member 59031025-Mar-10 21:27 
AnswerRe: localization issue Pin
KarstenK25-Mar-10 22:47
mveKarstenK25-Mar-10 22:47 
GeneralRe: localization issue Pin
Member 59031025-Mar-10 23:26
Member 59031025-Mar-10 23:26 
GeneralRe: localization issue Pin
Eugen Podsypalnikov25-Mar-10 23:35
Eugen Podsypalnikov25-Mar-10 23:35 
GeneralRe: localization issue Pin
Member 59031025-Mar-10 23:54
Member 59031025-Mar-10 23:54 
GeneralRe: localization issue Pin
Eugen Podsypalnikov26-Mar-10 0:03
Eugen Podsypalnikov26-Mar-10 0:03 
GeneralRe: localization issue Pin
Member 59031026-Mar-10 0:06
Member 59031026-Mar-10 0:06 
Questionrun under CScript Pin
john563225-Mar-10 20:37
john563225-Mar-10 20:37 
AnswerRe: run under CScript Pin
Richard MacCutchan26-Mar-10 0:29
mveRichard MacCutchan26-Mar-10 0:29 
QuestionRe: run under CScript Pin
David Crow26-Mar-10 4:54
David Crow26-Mar-10 4:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.