All pastes #26375 Raw Edit

Unnamed

public text v1 · immutable
#26375 ·published 2005-10-23 14:59 UTC
rendered paste body
//----------------------------- private --------------------------------------
unsigned int Student::parseRegNr(string reginput) {
	
	unsigned int r = 0;
	for (unsigned int i = 0; i < reginput.length(); i++) {
		// numbers are between ASCII code 30 and 39 hex
		if (reginput[i] >= 0x30 && reginput[i] <= 0x39) {
			
			// substract 0x30 from the input gives the 
			// value of the current decimal digit
			// this result is then added to the number
			r += reginput[i] - 0x30;
			
			// decimal left shift the number by one decimal digit
			// = multiplication by 10
			if (i < reginput.length() - 1) {
				r *= 10;
			}

		} else {
			return r;
		}
	}
	return r;
}