Code: /* dac.c - bipolar two's complement D/A converter */ double dac(int* b, int B, double R) { double dac = 0; b[0] = 1 - b[0]; for (int i=B-1; i>=0; i--) { dac = 0.5 * (dac + b[i]); } dac = R * (dac - 0.5); b[0] = 1 - b[0]; return dac; } Usage: double R = 10.0; int B = 4; int* b = new int[B]; b[0] = 1; b[1] = 0; b[2] = 1; b[3] = 0; xQ = dac(b, B, R);