Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   signed and unsigned value (http://www.velocityreviews.com/forums/t711903-signed-and-unsigned-value.html)

deepak 01-16-2010 02:41 AM

signed and unsigned value
 
Hi,

Could some one tell how signed and unsigned value considered in CPU.
Will they check most significant bit based on type of variable and
process
one way if it's signed and other way if it's unsigned variable.

Thanks,
Deepak

Andrew Poelstra 01-16-2010 03:26 AM

Re: signed and unsigned value
 
On 2010-01-16, deepak <deepakpjose@gmail.com> wrote:
> Hi,
>
> Could some one tell how signed and unsigned value considered in CPU.
> Will they check most significant bit based on type of variable and
> process
> one way if it's signed and other way if it's unsigned variable.
>


Lookup the term 'endianness' for bit ordering.
For signedness, try
2's complement
1's complement
signed magnitude

Wiki is your friend.

But neither of these questions are related to C.


Keith Thompson 01-16-2010 04:14 AM

Re: signed and unsigned value
 
Andrew Poelstra <apoelstra@localhost.localdomain> writes:
> On 2010-01-16, deepak <deepakpjose@gmail.com> wrote:
>> Could some one tell how signed and unsigned value considered in CPU.
>> Will they check most significant bit based on type of variable and
>> process
>> one way if it's signed and other way if it's unsigned variable.

>
> Lookup the term 'endianness' for bit ordering.
> For signedness, try
> 2's complement
> 1's complement
> signed magnitude
>
> Wiki is your friend.
>
> But neither of these questions are related to C.


Well, actually they are. The C standard (as of C99) specifies that
signed integers must use one the above three representations.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Barry Schwarz 01-31-2010 12:53 AM

Re: signed and unsigned value
 
On Fri, 15 Jan 2010 18:41:59 -0800 (PST), deepak
<deepakpjose@gmail.com> wrote:

>Hi,
>
>Could some one tell how signed and unsigned value considered in CPU.
>Will they check most significant bit based on type of variable and
>process
>one way if it's signed and other way if it's unsigned variable.


It would be unlikely that your approach could detect the difference
between a positive value stored in a signed object and the same value
stored in an unsigned object.

As far as the language is concerned, this is not a CPU issue. Whether
the CPU can deal with signed and unsigned distinctly (such as IBM
mainframes) or whether it can only deal with one type or the other, it
is always the compiler's job to generate the appropriate set of
instructions so that the result of the computation complies with the
standard.

--
Remove del for email


All times are GMT. The time now is 03:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.