Negative number representation across multiple architechture

Posted by Donotalo on Stack Overflow See other posts from Stack Overflow or by Donotalo
Published on 2010-04-24T16:21:19Z Indexed on 2010/04/24 16:23 UTC
Read the original article Hit count: 242

I'm working with OKI 431 micro controller. It can communicate with PC with appropriate software installed. An EEPROM is connected in the I2C bus of the micro which works as permanent memory. The PC software can read from and write to this EEPROM.

Consider two numbers, B and C, each is two byte integer. B is known to both the PC software and the micro and is a constant. C will be a number so close to B such that B-C will fit in a signed 8 bit integer. After some testing, appropriate value for C will be determined by PC and will be stored into the EEPROM of the micro for later use.

Now the micro can store C in two ways:

  • The micro can store whole two byte representing C
  • The micro can store B-C as one byte signed integer, and can later derive C from B and B-C

I think that two's complement representation of negative number is now universally accepted by hardware manufacturers. Still I personally don't like negative numbers to be stored in a storage medium which will be accessed by two different architectures because negative number can be represented in different ways. For you information, 431 also uses two's complement.

Should I get rid of the headache that negative number can be represented in different ways and accept the one byte solution as my other team member suggested? Or should I stick to the decision of the two byte solution because I don't need to deal with negative numbers? Which one would you prefer and why?

© Stack Overflow or respective owner

Related posts about general-development

Related posts about subjective