Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Binary Number?

Status
Not open for further replies.

Electroenthusiast

Active Member
How Do You say whether the Binary Number is signed / un-signed?

According to the concept;
the negative number has MSB as "1", whereas the positive as "0" as MSB...
But Given a number how will you say whether it is Signed/ Un-signed.
Atleast how Computer Knows?
 
How Do You say whether the Binary Number is signed / un-signed?

According to the concept;
the negative number has MSB as "1", whereas the positive as "0" as MSB...
But Given a number how will you say whether it is Signed/ Un-signed.
Atleast how Computer Knows?

hi,
Its the computer program subroutines that decides if a number should be processed as a signed or unsigned number, not the computer.:)
 
There is no inherent way to determine if a particular number is signed or unsigned. It is designated as one or the other when the number is generated.
 
You can't tell from a specific bit pattern if a number is signed or unsigned. 10110110 for example could be 128+32+16+4+2=182 or it could be -(64+8+2)=-74 (remember to get 2's complement of a number, flip the bits and add 1).

The difference between signed and unsigned is how it will be treated by the computer, so dividing the number by 2 would result in 01011011 if the number is unsigned (182/2=91) or 11011011 (sign extension) if it is signed (-74/2=-37).

Also if a number is signed then incrementing 01111111 will result in an overflow and possibly incorrect results (because the value will change from 127 to -128) but this is not a problem if the number is unsigned (127+1=128).

The range of 8-bit signed is -128..+127 and the range of 8-bit unsigned is 0..255.
 
Bits in memory have no meaning. It is up to the computer program to know if the bits are an instruction, string, number etc.

How does the computer know? In the case of compiled programs it knows because the compiler knows what the compiler(or linker) stored where in memory, we can still goof and use data of the wrong type. If we are lucky the compiler will catch it. In the case of asm it is up to the programmer(human) to ensure that he understands what he has stored at each memory location.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top