Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: mex gateway function
Posted:
Jan 3, 2013 6:02 PM


"Michal Kvasnicka" wrote in message <kc3uq0$t49$1@newscl01ah.mathworks.com>... > How to create suitable mex gateway function coresponduing to the following C function (decimal to binary conversion)? > > void deci2bin( int x, int n, double* output){ > double *temp; > int i; > temp = (double *)mxMalloc(sizeof(double)*n); > i=0; > while(x>=0 && i<n){ > temp[i] = x%2; > i++; > } > for(i=0;i<n;i++) > output[i] = temp[n1i]; > }
In addition to looking for a fast utility, you should probably be looking for a correct one as well. I don't see how the above routine can work at all since x is not altered during the while loop extracting the "bits" via the x%2 operation. Also, what is supposed to happen for negative x inputs? In the above code, you will end up copying unitialized memory into output for this case. Bottom line is the above code has bugs that need fixing.
James Tursa



