Preserving Hamming Distance in Arithmetic and Logical Operations