424,952 Members | 1,908 Online
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Sign-Magnitude Method of a signed 16bit int

 100+ P: 158 I am running in Linux x86 and I am wondering if there is a way to specify to use the Sign-Magnitude Method for representing a signed 16bit int. When i use int16_t as a data type it does not use that method but I need it to. Dec 9 '10 #1

No. C/C++ neither reveal nor allow you any control over the underlying representation of signed numbers.

6 Replies

 P: 9 Can you elaborate your question. I did not understand your requirement. Dec 9 '10 #2

 Expert Mod 5K+ P: 9,197 Both C and C++ use sign magnitude. It's a fancy way of saying the left bit is the sign bit. When the left bit is ON you have a negative number. BTW: Negative values are usually 2's complement. Postive values are not. Dec 9 '10 #3

 Expert 100+ P: 2,396 The most common technique for encoding signed integers is two's complement. However, it is not the only way to do it. One of the other techniques is signed-magnitude. In signed-magnitude encoding, the bit patterns for +n and -n differ only in the single sign bit. The question is whether this is what kardon33 meant by signed magnitude. Dec 9 '10 #4

 100+ P: 158 Thanks for the replies. Yes DoBock, I am trying to use the signed-magnitude method. Currently when I run my program it is not encoded in that method. I am wondering if it is possible to specify the encoding method. Currently I am using a work around by using an unsigned 16bit and limiting the domain to 0-32767 and then manually setting the first bit using bitwise operations. How ever this could lead to errors without strict checking what im setting. Dec 9 '10 #5

 Expert 100+ P: 2,396 No. C/C++ neither reveal nor allow you any control over the underlying representation of signed numbers. Dec 9 '10 #6

 100+ P: 158 Alright, thanks! Dec 9 '10 #7