d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Computer Binary > Signed Vs. None Signed.
12Next
Add Reply New Topic New Poll
Member
Posts: 35,456
Joined: Jan 25 2009
Gold: 1,173.00
Jan 30 2014 07:52pm
I've been studying binary computing in one of my classes and I am puzzled by a problem. 11111111 = 255. But if this number was signed, it would be 11111111 = -127. Obviously the first number designating that the number in question is now a negative. How does the computer distinguish between the number being 255 and -127. Is this done handled from the programmers perspective in the IDE and the computer follows a set of rules or is there a complex algorithm that was created to help a computer "think" which number is appropriate. Thanks guys.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 30 2014 09:58pm
Quote (NinjaSushi2 @ Jan 30 2014 08:52pm)
I've been studying binary computing in one of my classes and I am puzzled by a problem. 11111111 = 255. But if this number was signed, it would be 11111111 = -127. Obviously the first number designating that the number in question is now a negative. How does the computer distinguish between the number being 255 and -127. Is this done handled from the programmers perspective in the IDE and the computer follows a set of rules or is there a complex algorithm that was created to help a computer "think" which number is appropriate. Thanks guys.


provide a scenario where a computer needs to distinguish between the two. i can't think of one offhand. the whole idea of decimal numbers is a human concept since we're more comfortable with decimal. a computer isn't converting between the two internally. 111 is simply 111. it isn't converted to 7 anywhere.

programmers control memory however they see fit. if they want memory location 0x1000 to hold a signed integer, they'll read the bytes in such a way.

and i dont see how this has anything to do with an IDE.
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Jan 30 2014 10:44pm
as carteblanche hinted at: The computer only uses the 11111111. It is all in how the program interprets this value. If it is expecting ascii I think that would represent a "hard space".
Member
Posts: 35,456
Joined: Jan 25 2009
Gold: 1,173.00
Jan 30 2014 11:36pm
Ah I see. So the os hands down the initial machine code values. Then any other higher languages would modify such values as need fit.
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Jan 31 2014 05:21am
Quote (NinjaSushi2 @ Jan 30 2014 10:36pm)
Ah I see. So the os hands down the initial machine code values. Then any other higher languages would modify such values as need fit.


yeah but your use of the word modify is problematic. Lets take the binary value: 00110101, which in base10 is 53

add:
if you call a function that adds numbers with 00110101 with 00000001; you will get 00110110 or in base 10 you get 54

print
if you call a function that prints to the screen with 00110101; you will get "5" on the screen because base10 53 is ascii for the character "5"

pointer:
if you call a function to expects an memory location as an input with 00110101; the function will use whatever is stored in memory location 00110101 and use that as its input

silly:
you might even have a function that expects this kind of input based on each digit of binary:
male?:hashair?:over30?:likecupcakes?:collegegraduate?:HasDiabetes?:PlaysD2?:LikesTurtles: in which case 00110101 would mean: A woman, who is bald, who is over 30, who likes cupcakes, is not college graduate, has diabetes, does not play d2, and like turtles.
Member
Posts: 35,456
Joined: Jan 25 2009
Gold: 1,173.00
Jan 31 2014 05:46am
Quote (Azrad @ 31 Jan 2014 06:21)
A woman, who is bald, who is over 30, who likes cupcakes, is not college graduate, has diabetes, does not play d2, and like turtles.


Where can I meet this mysterious dream woman?
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Jan 31 2014 05:52am
Quote (NinjaSushi2 @ Jan 31 2014 04:46am)
Where can I meet this mysterious dream woman?


oh you like her? well check out this one:

01011011
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Jan 31 2014 05:56am
Quote (NinjaSushi2 @ Jan 31 2014 04:46am)
Where can I meet this mysterious dream woman?


oh damn, i should have passed you a pointer to her location in the ram...
Member
Posts: 35,456
Joined: Jan 25 2009
Gold: 1,173.00
Jan 31 2014 06:04am
Quote (Azrad @ 31 Jan 2014 06:52)
oh you like her? well check out this one:

01011011


Quote (Azrad @ 31 Jan 2014 06:56)
oh damn, i should have passed you a pointer to her location in the ram...


lol

This post was edited by NinjaSushi2 on Jan 31 2014 06:04am
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Jan 31 2014 10:21am
Like others have said it's the programmer/language's problem to figure this out. In the case of Java all integer values of varying word sizes (short, long and integer) are treated as signed. In C-like languages you often can specify whether or not you want a signed or unsigned integer value.
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll