Are negative signed integers, converted to binary, simply regular integers +256?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Are negative signed integers, converted to binary, simply regular negative integers +256?
00001010 = + 10 signed
00001010 = + 10 unsigned
11110110 = - 10 signed
11110110 = +246 unsigned (-10+256=246)
Notice how -10 (signed) is just -10+256=246 (unsigned)?
So in other words: If you want to represent a negative integer (such as -10) as a signed byte, you would simply add 256 before doing the base2 conversion?
I also heard that it can be done by "inverting all the bits and then adding one to the result".
PS: If it's not obvious, dealing with numbers isn't a strength of mine. I know that's probably not the case for most of you, but I'm trying to simplify the concept. Please keep that in mind, and if possible (respectfully) try to resist the urge to make it more confusing or complicated.
computer-science integers binary learning binary-operations
 |Â
show 1 more comment
up vote
0
down vote
favorite
Are negative signed integers, converted to binary, simply regular negative integers +256?
00001010 = + 10 signed
00001010 = + 10 unsigned
11110110 = - 10 signed
11110110 = +246 unsigned (-10+256=246)
Notice how -10 (signed) is just -10+256=246 (unsigned)?
So in other words: If you want to represent a negative integer (such as -10) as a signed byte, you would simply add 256 before doing the base2 conversion?
I also heard that it can be done by "inverting all the bits and then adding one to the result".
PS: If it's not obvious, dealing with numbers isn't a strength of mine. I know that's probably not the case for most of you, but I'm trying to simplify the concept. Please keep that in mind, and if possible (respectfully) try to resist the urge to make it more confusing or complicated.
computer-science integers binary learning binary-operations
2
There are different systems in use. E.g Two's complement and Ones' complement .
– mvw
Jul 15 at 15:41
2
Actually, for an integer (as opposed to signed char), you may have to add $4294967296$ or even $18446744073709551616$ instead of $256$ :)
– Hagen von Eitzen
Jul 15 at 15:45
A microprocessor manual will necessarily illustrate the format for signed integers (of varying "sizes"). Your magic constant 256 suggests you are thinking of signed bytes, but you should be aware that default integers are bigger than that on modern CPUs.
– hardmath
Jul 15 at 15:48
I think this would be two's complement. I'm not familar with any other. I tried to add a two's complement tag, but there wasn't one.
– tjt263
Jul 15 at 15:49
You can put "two's complement" in the search box on a MSE web page and get a list of mostly-relevant questions and answers.
– David K
Jul 15 at 16:36
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Are negative signed integers, converted to binary, simply regular negative integers +256?
00001010 = + 10 signed
00001010 = + 10 unsigned
11110110 = - 10 signed
11110110 = +246 unsigned (-10+256=246)
Notice how -10 (signed) is just -10+256=246 (unsigned)?
So in other words: If you want to represent a negative integer (such as -10) as a signed byte, you would simply add 256 before doing the base2 conversion?
I also heard that it can be done by "inverting all the bits and then adding one to the result".
PS: If it's not obvious, dealing with numbers isn't a strength of mine. I know that's probably not the case for most of you, but I'm trying to simplify the concept. Please keep that in mind, and if possible (respectfully) try to resist the urge to make it more confusing or complicated.
computer-science integers binary learning binary-operations
Are negative signed integers, converted to binary, simply regular negative integers +256?
00001010 = + 10 signed
00001010 = + 10 unsigned
11110110 = - 10 signed
11110110 = +246 unsigned (-10+256=246)
Notice how -10 (signed) is just -10+256=246 (unsigned)?
So in other words: If you want to represent a negative integer (such as -10) as a signed byte, you would simply add 256 before doing the base2 conversion?
I also heard that it can be done by "inverting all the bits and then adding one to the result".
PS: If it's not obvious, dealing with numbers isn't a strength of mine. I know that's probably not the case for most of you, but I'm trying to simplify the concept. Please keep that in mind, and if possible (respectfully) try to resist the urge to make it more confusing or complicated.
computer-science integers binary learning binary-operations
edited Jul 15 at 16:06
asked Jul 15 at 15:39


tjt263
1094
1094
2
There are different systems in use. E.g Two's complement and Ones' complement .
– mvw
Jul 15 at 15:41
2
Actually, for an integer (as opposed to signed char), you may have to add $4294967296$ or even $18446744073709551616$ instead of $256$ :)
– Hagen von Eitzen
Jul 15 at 15:45
A microprocessor manual will necessarily illustrate the format for signed integers (of varying "sizes"). Your magic constant 256 suggests you are thinking of signed bytes, but you should be aware that default integers are bigger than that on modern CPUs.
– hardmath
Jul 15 at 15:48
I think this would be two's complement. I'm not familar with any other. I tried to add a two's complement tag, but there wasn't one.
– tjt263
Jul 15 at 15:49
You can put "two's complement" in the search box on a MSE web page and get a list of mostly-relevant questions and answers.
– David K
Jul 15 at 16:36
 |Â
show 1 more comment
2
There are different systems in use. E.g Two's complement and Ones' complement .
– mvw
Jul 15 at 15:41
2
Actually, for an integer (as opposed to signed char), you may have to add $4294967296$ or even $18446744073709551616$ instead of $256$ :)
– Hagen von Eitzen
Jul 15 at 15:45
A microprocessor manual will necessarily illustrate the format for signed integers (of varying "sizes"). Your magic constant 256 suggests you are thinking of signed bytes, but you should be aware that default integers are bigger than that on modern CPUs.
– hardmath
Jul 15 at 15:48
I think this would be two's complement. I'm not familar with any other. I tried to add a two's complement tag, but there wasn't one.
– tjt263
Jul 15 at 15:49
You can put "two's complement" in the search box on a MSE web page and get a list of mostly-relevant questions and answers.
– David K
Jul 15 at 16:36
2
2
There are different systems in use. E.g Two's complement and Ones' complement .
– mvw
Jul 15 at 15:41
There are different systems in use. E.g Two's complement and Ones' complement .
– mvw
Jul 15 at 15:41
2
2
Actually, for an integer (as opposed to signed char), you may have to add $4294967296$ or even $18446744073709551616$ instead of $256$ :)
– Hagen von Eitzen
Jul 15 at 15:45
Actually, for an integer (as opposed to signed char), you may have to add $4294967296$ or even $18446744073709551616$ instead of $256$ :)
– Hagen von Eitzen
Jul 15 at 15:45
A microprocessor manual will necessarily illustrate the format for signed integers (of varying "sizes"). Your magic constant 256 suggests you are thinking of signed bytes, but you should be aware that default integers are bigger than that on modern CPUs.
– hardmath
Jul 15 at 15:48
A microprocessor manual will necessarily illustrate the format for signed integers (of varying "sizes"). Your magic constant 256 suggests you are thinking of signed bytes, but you should be aware that default integers are bigger than that on modern CPUs.
– hardmath
Jul 15 at 15:48
I think this would be two's complement. I'm not familar with any other. I tried to add a two's complement tag, but there wasn't one.
– tjt263
Jul 15 at 15:49
I think this would be two's complement. I'm not familar with any other. I tried to add a two's complement tag, but there wasn't one.
– tjt263
Jul 15 at 15:49
You can put "two's complement" in the search box on a MSE web page and get a list of mostly-relevant questions and answers.
– David K
Jul 15 at 16:36
You can put "two's complement" in the search box on a MSE web page and get a list of mostly-relevant questions and answers.
– David K
Jul 15 at 16:36
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
That works for $8-$bit signed integers on a twos' complement machine. General-purpose computers all use twos' complement these days, but there are programmable logic arrays that use sign-magnitude. If you are using a high-level language like C, don't do this yourself, but let the compiler take care of it, because it will work differently for different-sized integer types. If you are using a language with unlimited sized integers, like python, this system doesn't work at all.
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
That works for $8-$bit signed integers on a twos' complement machine. General-purpose computers all use twos' complement these days, but there are programmable logic arrays that use sign-magnitude. If you are using a high-level language like C, don't do this yourself, but let the compiler take care of it, because it will work differently for different-sized integer types. If you are using a language with unlimited sized integers, like python, this system doesn't work at all.
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
add a comment |Â
up vote
1
down vote
That works for $8-$bit signed integers on a twos' complement machine. General-purpose computers all use twos' complement these days, but there are programmable logic arrays that use sign-magnitude. If you are using a high-level language like C, don't do this yourself, but let the compiler take care of it, because it will work differently for different-sized integer types. If you are using a language with unlimited sized integers, like python, this system doesn't work at all.
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
add a comment |Â
up vote
1
down vote
up vote
1
down vote
That works for $8-$bit signed integers on a twos' complement machine. General-purpose computers all use twos' complement these days, but there are programmable logic arrays that use sign-magnitude. If you are using a high-level language like C, don't do this yourself, but let the compiler take care of it, because it will work differently for different-sized integer types. If you are using a language with unlimited sized integers, like python, this system doesn't work at all.
That works for $8-$bit signed integers on a twos' complement machine. General-purpose computers all use twos' complement these days, but there are programmable logic arrays that use sign-magnitude. If you are using a high-level language like C, don't do this yourself, but let the compiler take care of it, because it will work differently for different-sized integer types. If you are using a language with unlimited sized integers, like python, this system doesn't work at all.
answered Jul 15 at 15:49


saulspatz
10.7k21323
10.7k21323
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
add a comment |Â
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
I don't know anything about that, let's just stick with two's complement for now.
– tjt263
Jul 15 at 16:44
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
@tjt263 Well, everything but the remark on sign-magnitude is relevant to twos' complement.
– saulspatz
Jul 15 at 16:47
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
This isn't really for any particular scenario. I had an exam, and there were some questions I couldn't answer. They were simple conversion and questions. Some involved addition, etc.
– tjt263
Jul 15 at 16:59
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
@tjt263 In that context, adding $256$ is correct.
– saulspatz
Jul 15 at 17:01
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2852629%2fare-negative-signed-integers-converted-to-binary-simply-regular-integers-256%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
There are different systems in use. E.g Two's complement and Ones' complement .
– mvw
Jul 15 at 15:41
2
Actually, for an integer (as opposed to signed char), you may have to add $4294967296$ or even $18446744073709551616$ instead of $256$ :)
– Hagen von Eitzen
Jul 15 at 15:45
A microprocessor manual will necessarily illustrate the format for signed integers (of varying "sizes"). Your magic constant 256 suggests you are thinking of signed bytes, but you should be aware that default integers are bigger than that on modern CPUs.
– hardmath
Jul 15 at 15:48
I think this would be two's complement. I'm not familar with any other. I tried to add a two's complement tag, but there wasn't one.
– tjt263
Jul 15 at 15:49
You can put "two's complement" in the search box on a MSE web page and get a list of mostly-relevant questions and answers.
– David K
Jul 15 at 16:36