I was just thinking if we could get rid of the bits which represent sign.
That's not how numbers (binary) work in a computer. The magnitude of the number is directly related to the number of bytes. The Most Significant Bit (MSB) is used to sigh the number. This technique allow the number to be split in half. An MSB of 1 means
negative while 0 is positive.
The characters that you see on the screen is actually an encoded. The string that represents -1234 is 5 bytes if ASCII is used but can be larger depending on the encoding.
Anyway, that's probably more than you need to know. I recommend, as always, reading the reference docs.
Member
92 Points
534 Posts
Should we use unsigned int to save space
Mar 13, 2019 07:14 AM|fatihbarut|LINK
Hi all,
In SQL server if we use unsigned int or smallint instead of signed ones can we save space?
Is it a commonly used technique
All-Star
53121 Points
23672 Posts
Re: Should we use unsigned int to save space
Mar 13, 2019 10:59 AM|mgebhard|LINK
A SMALLINT is 2 bytes while an INT is 4 bytes.
Signed and unsigned refers to binary numbers that can have a negative values but are the same size in bytes.
Use a small int if the values you are saving never exceed the max size +32,768 / -32,767.
Member
92 Points
534 Posts
Re: Should we use unsigned int to save space
Mar 13, 2019 11:02 AM|fatihbarut|LINK
I was just thinking if we could get rid of the bits which represent sign.
All-Star
53121 Points
23672 Posts
Re: Should we use unsigned int to save space
Mar 13, 2019 11:41 AM|mgebhard|LINK
That's not how numbers (binary) work in a computer. The magnitude of the number is directly related to the number of bytes. The Most Significant Bit (MSB) is used to sigh the number. This technique allow the number to be split in half. An MSB of 1 means negative while 0 is positive.
The characters that you see on the screen is actually an encoded. The string that represents -1234 is 5 bytes if ASCII is used but can be larger depending on the encoding.
Anyway, that's probably more than you need to know. I recommend, as always, reading the reference docs.