BigNat - /* Michael Boynton ECE209 - 604 17 April 2008 *...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Michael Boynton ECE209 - 604 17 April 2008 * BigNat implementation for ECE209 * * Implementation with linked lists * * This implementation illustrates the (heavy) use of recursion. * To simplify the code, there is no checking for malloe failure! * * J Dean Brock, (c) 2008 */ #include "BigNat.h" #include <stdlib.h> /* prototypes for internal routines */ static int countChars(BigNat) ; static BigNat addBigNatWithCarry(BigNat, BigNat, unsigned int) ; static BigNat multiplyInts(unsigned int, unsigned int) ; static BigNat addZeros(BigNat) ; /* end of internal routine prototypes */ BigNat createBigNat (unsigned int num) { BigNat retNode ; unsigned int pLow, pHigh ; retNode = malloc(sizeof(struct bnStruct)) ; pLow = num%1000000000 ; /* Initial number could be > 1,000,000,000 */ pHigh = num/1000000000 ; retNode -> value = pLow ; if (pHigh > 0) { BigNat nxtNode = malloc(sizeof(struct bnStruct)) ; nxtNode -> value = pHigh ; nxtNode -> next = NULL ; retNode -> next = nxtNode ; } else { retNode -> next = NULL ; } return retNode ; } BigNat addBigNat (BigNat x, BigNat y) { return addBigNatWithCarry(x, y, 0) ; } BigNat mulBigNat (BigNat x, BigNat y) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/21/2009 for the course ECE 209 taught by Professor Tuck during the Spring '08 term at N.C. State.

Page1 / 4

BigNat - /* Michael Boynton ECE209 - 604 17 April 2008 *...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online