/* binsucc.c: binary successor operation on a binary (integer) vector i.e. if v is a vector of 0's and 1's of the binary representation of an integer k using d binary digits (k=0,...,2^d-1 where d=rows(v)), then binsucc(v) returns the binary representation of k+1 Note that the successor of a vector of all 1's would require d+1 digits (e.g. the successor of 1111, (binary representation of 15) is the 5 digit number 10000 (binary representation of 16). This procedure returns a warning in this case and gives a d+1 digit return vector) John Rust, University of Maryland, February, 2004 */ void binsucc(int *v,int d) { int i; if (v[d-1] == 1) { v[d-1]=0; v[d-2]=v[d-2]+1; } else { v[d-1]=1; } for (i=d-2; i>=0; i--) { if (v[i] > 1) { if (i > 0) { v[i]=0; v[i-1]=v[i-1]+1; } else { v[0]=0; } } } }