function status = bwrite( fid, bits, value );
%This function takes a matrix and writes it out to a bit stream in UNIX.

if( bits > 0 ),
  if( value > 2^(bits-1) -1 ) value = 2^(bits-1) -1; end
  if( value < -(2^(bits-1)) ) value = -(2^(bits-1)); end
    status = fwrite( fid, value, sprintf('bit%d',bits));
end



