Hi,
On 2 Dez., 17:43, "Agung Prasetyo" <[EMAIL PROTECTED]> wrote: > Hi everybody, would you like to help me please ? > i am very confuse about Exercise 4.2 at Lab-1022, what is the Checksum and > Adler32, what is that function? Checksum is an interface defined in the lab, which tells you which methods you have to implement. After this every class implementing this interface can be used, so you can change the checksum implementation if you obey the interface definition. Adler32 is a checksum algorithm see http://en.wikipedia.org/wiki/Adler-32 for an explanation. > and what is this following codes mean ? As mentioned before. The Class Adler32 implements the Interface Checksum to support all necessary methods and the Algorithm Adler32 ( so I hope ) is implemented. > > public class Adler32 implements Checksum { > private int value = 1; > > /* > * BASE is the largest prime number smaller than 65536 > * NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 > */ > private static final int BASE = 65521; > private static final int NMAX = 5552; > > /** > * Update current Adler-32 checksum given the specified byte. > */ > public void update(int b) { > int s1 = value & 0xffff; > int s2 = (value >> 16) & 0xffff; > s1 += b & 0xff; > s2 += s1; > value = ((s2 % BASE) << 16) | (s1 % BASE); > } > > /** > * Update current Adler-32 checksum given the specified byte array. > */ > public void update(byte[] b, int off, int len) { > int s1 = value & 0xffff; > int s2 = (value >> 16) & 0xffff; > > while (len > 0) { > int k = len < NMAX ? len : NMAX; > len -= k; > while (k-- > 0) { > s1 += b[off++] & 0xff; > s2 += s1; > } > s1 %= BASE; > s2 %= BASE; > } > value = (s2 << 16) | s1; > } > > /** > * Reset Adler-32 checksum to initial value. > */ > public void reset() { > value = 1; > } > > /** > * Returns current checksum value. > */ > public long getValue() { > return (long)value & 0xffffffff; > }} > > =-=-===================--==-=-===========-==-=-==-================== > After exercise 4.2, i have few questions again about the homework, > how did you do to convert the characters to upper case? > Did you use any java methods or use a *bit operation* (bitwise) to convert > characters to uppercase ? Because this course is for learning java, I would use java methods to get the uppercase Character. > May we use the arithmetic operator like this code, to convert it ? > ex : > *int x = 'a'; > int y = x-32; //minus > //so the value of y is 65 > System.out.printf("%c",y); > > --> output = A > * > because the x decimal value is 97 and a hexadecimal value is 61, > and i know the decimal value of *'A' =65*, so i substract the value of x > with 32 and give to y. > > Please help me, i have got few problems are difficult to understand in this > Lab-1022 > *I am sorry if i my english is not good. Thanks* HTH Ewald --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
