Representation Formula for Binary Sums Modulo $q$