Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #5641

Re: Question

From Ben Pfaff <blp@cs.stanford.edu>
Newsgroups comp.lang.c
Subject Re: Question
Date 2011-06-08 10:36 -0700
Message-ID <8739jkmdin.fsf@blp.benpfaff.org> (permalink)
References <cbbad7e4-3532-4062-b39e-e4ad92a34f9d@p13g2000yqh.googlegroups.com>

Show all headers | View raw


Mateusz_madi <madi.czadi@gmail.com> writes:

> char c= -1;
> int x;
> x=c;
> printf("%d", x);
>
> Result:
> -1
>
> Why it is -1? How -1 is represented in char in binary format?

Presumably 'char' is a signed type.  It shouldn't be surprising
that a signed integer type should be able to store -1.

The most common way to store -1 as a binary integer is with all
1-bits.
-- 
Ben Pfaff 
http://benpfaff.org

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Question Mateusz_madi <madi.czadi@gmail.com> - 2011-06-08 10:31 -0700
  Re: Question Ben Pfaff <blp@cs.stanford.edu> - 2011-06-08 10:36 -0700
    Re: Question Mateusz_madi <madi.czadi@gmail.com> - 2011-06-08 10:49 -0700
      Re: Question Ben Pfaff <blp@cs.stanford.edu> - 2011-06-08 10:54 -0700
        Re: Question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-08 12:49 -0600
          Re: Question Keith Thompson <kst-u@mib.org> - 2011-06-08 11:55 -0700
            Re: Question Ben Pfaff <blp@cs.stanford.edu> - 2011-06-08 12:21 -0700
              Re: Question "Kleuskes & Moos" <kleuske@xs4all.nl> - 2011-06-08 16:02 -0700
              Re: Question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-08 17:31 -0600
            Re: Question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-08 17:30 -0600
            Re: Question Peter Nilsson <airia@acay.com.au> - 2011-06-08 16:34 -0700
      Re: Question "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-06-08 16:52 -0400
        Re: Question Ben Pfaff <blp@cs.stanford.edu> - 2011-06-08 13:54 -0700
          Re: Question "J. J. Farrell" <jjf@bcs.org.uk> - 2011-06-09 03:22 +0100
  Re: Question Keith Thompson <kst-u@mib.org> - 2011-06-08 10:47 -0700

csiph-web