13

I've been reading a few sites, but none of them make sense to me. Is signed and unsigned binary them same as signed and unsigned variables. I'd be glad if you could help :)

R.M.R
  • 193
  • 1
  • 2
  • 9
  • Signed and Unsigned Binary refers to the conversion that depends on sign of the binary represented. Whereas for the variables it refers to having the variable able to store the negative value or not. – Smit Mar 05 '17 at 02:10
  • But what's the difference between signed and unsigned binary? – R.M.R Mar 05 '17 at 02:11
  • I'm late to the party, but just a note: if I see "signed/unsigned binary", I'd be thinking of [signing binaries (e.g. exe/dlls)](https://en.wikipedia.org/wiki/Code_signing) rather than a variable's data type. – mcmlxxxvi Nov 19 '20 at 11:37

4 Answers4

17

The "signed" indicator means that the item can hold positive or negative values. "Unsigned" doesn't distinguish between positive and negative values. A signed/unsigned variable can refer to any numerical data type (such as binary, integer, float, etc). Each data type might be further defined as signed or unsigned.

For example, an 8-bit signed binary could hold values from 0-127, both positive and negative (1 bit is used for the sign and 7 bits for the value), while an 8-bit unsigned binary could hold values from 0-255 (nothing distinguishes whether or not the value should be considered positive or negative, though it is commonly assumed to be positive).

A signed binary is a specific data type of a signed variable.

Hope that helps!

  • signed can represent positive and negative numbers – R.M.R Mar 05 '17 at 02:19
  • @R.M.R. Yes, signed can represent both positive and negative numbers. – Joel Stanford Mar 05 '17 at 02:21
  • Can you just explain about unsigned again. Sorry to be a little awkward I just don't quite understand it yet. – R.M.R Mar 05 '17 at 02:23
  • 1
    Unsigned means that there is nothing in the value that indicates if the number is considered to be positive or negative - it's just a value with out a sign (sign = "-" or "+"). Commonly, it is considered to be a positive value. – Joel Stanford Mar 05 '17 at 02:26
  • My previous comment could have described an unsigned binary, or an unsigned variable. I'm afraid this might be confusing, but an unsigned binary could be a type of unsigned variable (for a metaphor, this is similar to saying that a granny smith apple is a type of apple. "Apple" is a larger category than the more specific "granny smith apple"). – Joel Stanford Mar 05 '17 at 02:32
  • So... Unsigned binary is the same as an unsigned variable? (again apologies if I'm annoying you) – R.M.R Mar 05 '17 at 02:35
  • @R.M.R If you are happy with either answer, above, you should mark one of them as correct (click the green check mark). – Joel Stanford Mar 05 '17 at 02:36
  • Unsigned binary could be a type of unsigned variable. An unsigned variable could be an unsigned binary, an unsigned integer, an unsigned float, or others... – Joel Stanford Mar 05 '17 at 02:37
  • Oh- so would I be correct in saying this: Unsigned binary has no indicator that determines it is positive or negative. However, it is usually considered as a positive value. – R.M.R Mar 05 '17 at 02:40
  • @R.M.R Yes, that would be correct. If this is for school homework, I might leave off the "However,..." phrase. Just use the first statement as that is factually correct. – Joel Stanford Mar 05 '17 at 02:41
  • Yes! I finally understand it! Thank you so much for helping me and yes I will press the little tick! I hope I am able to help you in the future too! :D Okay thanks for that last part too :) – R.M.R Mar 05 '17 at 02:43
4

A "signed" variable means that the value holds a positive or negative value using it's most significant bit (the last bit to the left), which is what we call the "signed bit". An "unsigned" variable does not, but instead the most significant bit is just the next power of two.

We call a signed bit that is 1 a negative number whereas on an unsigned number the bit would fall under the regular binary bit rules.

For example max values look like this:
Unsigned Char 0b11111111 (0xFF in hex) = 255 in decimal, (128+64+32+16+8+4+2+1 = 255)
Signed Char 0b11111111 (0xFF in hex) = -127 in decimal, (-1 * (64+32+16+8+4+2+1) = - 127)

Additionally what you might see in code:
Unsigned Char 0b10000001 (0x81 in hex) = 129 in decimal, (128 + 1 = 129)
Signed Char 0b10000001 (0x81 in hex) = -1 in decimal, (-1 * 1)

(Note: char is one byte which means it has eight digits in binary that can be changed)
(For anyone who is wondering, 0b means the bit is in binary and 0x means it is in hex)

Kenneth
  • 61
  • 7
3

Signed and Unsigned Binary refers to the conversion that depends on sign of the binary represented. Whereas for the variables it refers to having the variable able to store the negative value or not.

In Binary for signed bit: We say 1 is negative and 0 is positive. So if you see second example, the first bit is 1 means? - right, its negative. And we dont include it for the conversion base2 to base10.

For example: 1001 In Unsigned bit (dont care about sign) : 9

For example: 1001 In Signed bit (MSB is a sign bit): -1

For variables is it very likely that stores negative numbers.

MSB: Most Significant Bit

Smit
  • 2,078
  • 2
  • 17
  • 40
1

It depends on the position or situation. Example,in assembly, We want to load byte have value: 0xFF(~11111111 in binary) from memory. $s3 have address of this value.

  • with func lbu( load byte unsignal ), it only allows to load unsignal binary: lb rt, offset(rs).

    • lbu $s0, 32($s3) : lbu will load value and 0-extend to 32 bit 0x000000FF which is interpreted as 255.
  • with func addi, it allows to load signal binary: lb rt, ofset(rs).
    • lb $s0, 32($s3) : lb will load value and 1-extend to 32 bit 0xFFFFFFFF which is interpreted as -1.
ducPham
  • 31
  • 1
  • 3