node1 *radix_sort(node1 *rec) { node1 *r, *nex; int poc = 0 ; int i, j, k; int larg = large(rec); int m = numdig(larg); /* These statements create pockets */ for(k = 0 ; k < 10; k++) { pocket[k] = (node1 *)malloc(sizeof(node1)); pocket1[k] = (node1 *)malloc(9*sizeof(node1)); } /* These statements initialize pockets */ for(j = 1; j <= m ; j++) { for(i = 0 ; i < 10 ; i++) { pocket[i] = NULL; pocket1[i] = NULL ; } r = rec ; while(r != NULL) { int dig = digit(r->data, j); nex = r->next ; update(dig,r); r = nex; } if(r!= NULL) { int dig = digit(r->data,j); update(dig,r); } while(pocket1[poc] == NULL) poc ++; rec = Make_link(poc, rec); } return(rec); }
char * maknew(char *str) { /* make two numerical fields */ int c; char *dpoint, *p, *q, *ba; p = str; for (ba= 0; c = *str; str++) if (c == '\\' && *(str+1)== '&') ba=str; str=p; if (ba==0) { for (dpoint=0; *str; str++) { if (*str=='.' && !ineqn(str,p) && (str>p && digit(*(str-1)) || digit(*(str+1)))) dpoint=str; } if (dpoint==0) for(; str>p; str--) { if (digit( * (str-1) ) && !ineqn(str, p)) break; } if (!dpoint && p==str) /* not numerical, don't split */ return(0); if (dpoint) str=dpoint; } else str = ba; p =str; if (exstore ==0 || exstore >exlim) { exstore = chspace(); exlim= exstore+MAXCHS; } q = exstore; ba = exstore + MAXSTR; do { if (exstore > ba) error(gettext("numeric field too big")); } while (*exstore++ = *str++); *p = 0; return(q); }
/*void insertParentProxy(ConfigVariablePtr var,AtomPcharKey=(unsigned char*)key;tr av) //add { AtomPtr atom; atom=*var->value.a; while(1){ //if(!atom->next)break; if(strcmp(atom->string,av->string)==0)return; if(!atom->next)break; atom=atom->next; } av->next=atom->next; atom->next=av; //av->next=*var->value.a; //*var->value.a=av; return; }*/ static int parseAtom1(char *buf, int offset, AtomPtr *value_return, int insensitive) { int y0, i, j, k; AtomPtr atom; int escape = 0; char *s; i = offset; if(buf[i] != '\0') { y0 = i; i++; while(buf[i] != '\"' && buf[i] != '\n' && buf[i] != '\0' && buf[i]!=',') { if(buf[i] == '\\' && buf[i + 1] != '\0') { escape = 1; i += 2; } else i++; } //if(buf[i] != '\0') //return -1; j = i ; } else { y0 = i; while(letter(buf[i]) || digit(buf[i]) || buf[i] == '_' || buf[i] == '-' || buf[i] == '~' || buf[i] == '.' || buf[i] == ':' || buf[i] == '/') i++; j = i; } if(escape) { s = malloc(i - y0); if(buf == NULL) return -1; k = 0; j = y0; while(j < i) { if(buf[j] == '\\' && j <= i - 2) { s[k++] = buf[j + 1]; j += 2; } else s[k++] = buf[j++]; } if(insensitive) atom = internAtomLowerN(s, k); else atom = internAtomN(s, k); free(s); j++; } else { if(insensitive) atom = internAtomLowerN(buf + y0, i - y0); else atom = internAtomN(buf + y0, i - y0); } *value_return = atom; return j; }
static void expand(const char *as) { const char *cs; const char *oldcs; char *sgpathp; struct stat stb; sgpathp = gpathp; cs = as; if (*cs == '~' && gpathp == gpath) { addpath('~'); for (cs++; letter(*cs) || digit(*cs) || *cs == '-';) addpath(*cs++); if (!*cs || *cs == '/') { if (gpathp != gpath + 1) { *gpathp = 0; if (gethdir(gpath + 1)) globerr = "Unknown user name after ~"; /* * Was: strcpy(gpath, gpath + 1); * but that's WRONG */ memmove(gpath, gpath+1, strlen(gpath+1)+1); } else { (void) strcpy(gpath, home); } gpathp = strend(gpath); } } while (!any(*cs, globchars)) { if (*cs == 0) { if (!globbed) Gcat(gpath, ""); else if (stat(gpath, &stb) >= 0) { Gcat(gpath, ""); globcnt++; } goto endit; } addpath(*cs++); } oldcs = cs; while (cs > as && *cs != '/') cs--, gpathp--; if (*cs == '/') cs++, gpathp++; *gpathp = 0; if (*oldcs == '{') { (void) execbrc(cs, ((char *)0)); return; } matchdir(cs); endit: gpathp = sgpathp; *gpathp = 0; }
void insertR(link& h, T x, int d){ int i = digit(x.key(), d); if(i == 0) h = new node(i); if(i == NULLdigit) return; if(i < h->d) insertR(h->l, x, d); if(i == h->d) insertR(h->m, x, d); if(i > h->d) insertR(h->r, x, d); }
void number (int a, int base) { n=1; while (base<a/n+1) n*=base; while (n) { digit (a/n); a%=n; n/=base; } }
int main(void) { int num=12345678, pos=5; printf("Posicion %d de %d es %d\n", pos, num, digit(pos, num) ); printf("Posicion %d de %d es %d\n", pos, num, digit_v2(pos, num) ); system("pause"); // Detiene la consola }
void number (int a, int base) { i=1; while (base<a/i+1) i*=base; while (i) { digit (a/i); a%=i; i/=base; } }
int getdigit(char c) { int i; lexval=0; lexval=c-'0'; /*lexval=int hi=0, c=char*/ if (thechar=='x') thechar='X'; if (thechar=='X') { next(); while(letter(thechar)) { c=next(); if(c>96) c=c-39; if (c>64) c=c-7; c=c-48; lexval=lexval << 4; /* *16 */ i=0; i=c; lexval=lexval+i;} }else { while(digit(thechar)) { c=next(); c=c-48; lexval=lexval*10; i=0; i=c; lexval=lexval+i; } } }
T searchR(link h, key v, int d){ if(h == 0) return nullItem; key t = h->item.key(); if(v == t) return h->item(); if(digit(v, d) == 0) return searchR(h->l, v); else return searchR(h->r, v); }
void tdc::enableFIFO() { unsigned int DATA; TestError(readData(ControlRegister, &DATA),"TDC: Enabling the FIFO"); if (digit(DATA,8)==0) { DATA+=0x0100;} TestError(writeData(ControlRegister, &DATA),"TDC: Enabling the FIFO"); if(vLevel(NORMAL))cout<<"FIFO enabled !"<<endl; }
//=================================================================== BYTE Convert_n(BYTE n) { BYTE i,s=0; for(i=0;i<8;i++) { s|=digit(n,i)<<(7-i); } return s; }
// graphics_open(3*w,62); int countdown(int strt, int fin, int br, int bg, int bb, int dr, int dg, int db, int m, int w) { int i,j,d1,d2,d3; while(BCHK); // debounce for(i=strt;i>=fin;i--) { graphics_fill(br,bg,bb); d1=i/100; d2=(i%100)/10; d3=i%10; if (d1>0) digit(d1,m,dr,dg,db); if (d1>0 || d2>0) digit(d2,m+w,dr,dg,db); digit(d3,m+w+w,dr,dg,db); graphics_update(); for (j=0;j<4;j++) { // pause 1 second or quit if(BCHK) return 1; msleep(250); } } return 0; }
unsigned long int decimal(char *ptr) { unsigned long result = 0; while (*ptr) { result *= 10; result += digit(*ptr++); } return result; }
/** * Figure out the answer numerically to each of the digit locations */ long faster() { int digits[] = {9, 90*2, 900*3, 9000*4, 90000*5, 900000*6}; int answer = 1; for (int ii = 1; ii <= 1000000; ii *= 10) { answer *= digit(ii,digits); } return answer; }
/* Returns the node matching the key or its prefix */ static patricia * pat_search(patricia *node, im_key key, int bit) { assert(node); if (node->bit <= bit) return node; else return pat_search(node->links[digit(key, node->bit)], key, node->bit); }
void do_msd_radixsort(item_t *array,int left,int right,int w) { int n=right-left+1; item_t *aux; int count[R+1]; int i; if(right-left+1<=1 || w>=bytesword){ return; } for(i=0;i<=R;i++){ count[i]=0; } for(i=left;i<=right;i++){ count[digit(array[i],w)+1]++; } for(i=1;i<=R;i++){ count[i]+=count[i-1]; } aux=malloc(n*sizeof(*aux)); for(i=left;i<=right;i++){ copy_item(&aux[count[digit(array[i],w)]++],&array[i]); } for(i=left;i<=right;i++){ copy_item(&array[i],&aux[i-left]); } free(aux); do_msd_radixsort(array,left,left+count[0]-1,w+1); for(i=1;i<R;i++){ do_msd_radixsort(array,left+count[i-1],left+count[i]-1,w+1); } }
void insertion_sort_radix(item_t *array,int left,int right,int w) { int i,j; item_t t; for(i=left+1; i<=right; i++) { copy_item(&t,&array[i]); for(j=i; j>left; j--) { if(digit(array[j-1],w)<=digit(t,w)) { break; } copy_item(&array[j],&array[j-1]); } copy_item(&array[j],&t); } }
static void expand(char *as) { char *cs; char *sgpathp, *oldcs; struct stat stb; sgpathp = gpathp; cs = as; if (*cs == '~' && gpathp == gpath) { addpath('~'); for (cs++; letter(*cs) || digit(*cs) || *cs == '-';) addpath(*cs++); if (!*cs || *cs == '/') { if (gpathp != gpath + 1) { *gpathp = 0; if (gethdir(gpath + 1)) { (void)sprintf(errstring = errbuf, "Unknown user name: %s after '~'", gpath+1); globerr = IPS; } strcpy(gpath, gpath + 1); } else strcpy(gpath, home); gpathp = strend(gpath); } } while (!any(*cs, globchars) && globerr == 0) { if (*cs == 0) { if (!globbed) Gcat(gpath, ""); else if (stat(gpath, &stb) >= 0) { Gcat(gpath, ""); globcnt++; } goto endit; } addpath(*cs++); } oldcs = cs; while (cs > as && *cs != '/') cs--, gpathp--; if (*cs == '/') cs++, gpathp++; *gpathp = 0; if (*oldcs == '{') { (void)execbrc(cs, ((char *)0)); return; } matchdir(cs); endit: gpathp = sgpathp; *gpathp = 0; }
double ParseDouble ( char **str ) { double num ; /* Skip nonnumeric stuff. If we run into a comma, that means missing data. */ while (! ( digit ( **str ) || (**str == '-') || (**str == '.'))) { if (**str == ',') { ++(*str) ; return MISSING ; // In CONST.H } if (**str) ++(*str) ; else return MISSING ; } /* Read the number, then pass it by */ num = atof ( *str ) ; while (digit ( **str ) || (**str == '-') || (**str == '.')) ++(*str) ; /* Skip a single comma that may be a delimiter */ while ((**str == ' ') || (**str == ',')) { if (**str == ',') { ++(*str) ; break ; } ++(*str) ; } return num ; }
inline bool set_number(unsigned int &_num) { unsigned int num = 0; for(unsigned int i = 0; i < n; ++i) { unsigned int d; if(!digit(c[i], d)) return false; num = num * 10 + d; } _num = num; return true; }
int main( void ) { printf("Enter a positive number, and a digit position: "); int number, position; scanf("%d %d", &number, &position); printf("The digit in position %d is %d", position, digit(number, position)); return EXIT_SUCCESS; }
radix_sort() { int i,k,dig,maxdig,mindig,least_sig,most_sig; struct node *p, *rear[10], *front[10]; least_sig=1; most_sig=large_dig(start); for(k = least_sig; k <= most_sig ; k++) { printf("PASS %d : Examining %dth digit from right ",k,k); for(i = 0 ; i <= 9 ; i++) { rear[i] = NULL; front[i] = NULL ; } maxdig=0; mindig=9; p = start ; while( p != NULL) { /*Find kth digit in the number*/ dig = digit(p->info, k); if(dig>maxdig) maxdig=dig; if(dig<mindig) mindig=dig; /*Add the number to queue of dig*/ if(front[dig] == NULL) front[dig] = p ; else rear[dig]->link = p ; rear[dig] = p ; p=p->link;/*Go to next number in the list*/ }/*End while */ /* maxdig and mindig are the maximum amd minimum digits of the kth digits of all the numbers*/ printf("mindig=%d maxdig=%d\n",mindig,maxdig); /*Join all the queues to form the new linked list*/ start=front[mindig]; for(i=mindig;i<maxdig;i++) { if(rear[i+1]!=NULL) rear[i]->link=front[i+1]; else rear[i+1]=rear[i]; } rear[maxdig]->link=NULL; printf("New list : "); display(); }/* End for */ }/*End of radix_sort*/
static int parseTime(char *line, int i, int *value_return) { int v = 0, w; while(1) { if(!digit(line[i])) break; w = atoi(line + i); while(digit(line[i])) i++; switch(line[i]) { case 'd': v += w * 24 * 3600; i++; break; case 'h': v += w * 3600; i++; break; case 'm': v += w * 60; i++; break; case 's': v += w; i++; break; default: v += w; goto done; } } done: *value_return = v; return i; }
T searchR(link h, key v, int d){ int i = digit(v, d); if(h == 0) return nullItem; if(i == NULLdigit){ T dummy(v); return dummy; } if(i < h->d) return searchR(h->l, v, d); if(i == h->d) return searchR(h->m, v, d); if(i > h->d) return searchR(h->r, v, d); }
int main() { int n = 287687665; int k = 1; printf("The %dth number in the integer %d is %d", k, n, digit(n,k)); getchar(); getchar(); return 0; }
void lsd_radixsort(item_t *array,int left,int right) { int i; int w; int n=right-left+1; int count[R+1]; item_t *aux; if(right-left+1<=1){ return; } aux=malloc(n*sizeof(*aux)); for(w=bytesword-1;w>=0;w--){ for(i=0;i<=R;i++){ count[i]=0; } for(i=left;i<=right;i++){ count[digit(array[i],w)+1]++; } for(i=1;i<=R;i++){ count[i]+=count[i-1]; } for(i=left;i<=right;i++){ copy_item(&aux[count[digit(array[i],w)]++],&array[i]); } for(i=left;i<=right;i++){ copy_item(&array[i],&aux[i-left]); } } free(aux); }
int mod(long long int n) { long long int x,j,m=0; len=strlen(num); a=digit(n); m=create(); // printf("1: m=%lld i=%lld\n",m,i); while(1) { m=remainder(m,n); // printf("2: m=%lld i=%lld\n",m,i); if(i>=len)break; if(m==0) { m=create(); // printf("3: m=%lld i=%lld\n",m,i); long long z=(digit(m)); // printf("a= %lld %lld\n",a,z); if(digit(m)!=a)break; } else { m*=10; m+=(num[i++]-48); // printf("4: m=%lld i=%lld\n",m,i); } } // printf("5: m=%lld i=%lld\n",m,i); if(m==0) return 1; else return 0; }
bool Reader::decodeNumber( Token &token ) { bool isDouble = false; for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) { isDouble = isDouble || in( *inspect, '.', 'e', 'E', '+' ) || ( *inspect == '-' && inspect != token.start_ ); } if ( isDouble ) return decodeDouble( token ); // Attempts to parse the number as an integer. If the number is // larger than the maximum supported value of an integer then // we decode the number as a double. Location current = token.start_; bool isNegative = *current == '-'; if ( isNegative ) ++current; Value::LargestUInt maxIntegerValue = isNegative ? Value::LargestUInt(-Value::minLargestInt) : Value::maxLargestUInt; Value::LargestUInt threshold = maxIntegerValue / 10; Value::LargestUInt value = 0; while ( current < token.end_ ) { Char c = *current++; if ( c < '0' || c > '9' ) return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); Value::UInt digit(c - '0'); if ( value >= threshold ) { // We've hit or exceeded the max value divided by 10 (rounded down). If // a) we've only just touched the limit, b) this is the last digit, and // c) it's small enough to fit in that rounding delta, we're okay. // Otherwise treat this number as a double to avoid overflow. if (value > threshold || current != token.end_ || digit > maxIntegerValue % 10) { return decodeDouble( token ); } } value = value * 10 + digit; } if ( isNegative ) currentValue() = -Value::LargestInt( value ); else if ( value <= Value::LargestUInt(Value::maxInt) ) currentValue() = Value::LargestInt( value ); else currentValue() = value; return true; }
void LaosDisplay::ShowScreen(const char *l, int *arg, char *s) { char c, next=0,surpress=1; char str[128],*p; p = str; *p++ = _I2C_HOME; while ( *l ) { c=*l; switch ( c ) { case '$': if (s != NULL && *s) c = *s++; else c = ' '; break; case '+': if (arg != NULL && *arg < 0) c = '-'; else c = '+'; break; case '0': next=1; surpress=0; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': char d = ' '; if (arg != NULL ) { d = digit(*arg, *l-'0'); if ( d == '0' && surpress ) // supress leading zeros d = ' '; else surpress = 0; if ( next && arg != NULL ) // take next numeric argument { arg++; next=0; surpress=1; } } c = d; break; } *p++ = c; l++; } *p=0; write(str); }