how integer stored in binary format in 'c' language

This is a discussion on how integer stored in binary format in 'c' language within the C Programming forums, part of the General Programming Boards category; how integer stored in binary format in 'c' language, plz give detail internal structure...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Thumbs up how integer stored in binary format in 'c' language

    how integer stored in binary format in 'c' language, plz give detail internal structure

  2. #2
    apprentiCe
    Join Date
    Oct 2008
    Location
    Hyderabad,India
    Posts
    136
    as zeros and ones ofcourse...



    if you wish to know how a c program is compiled linked and loaded and executed then see this link
    Hello World Program
    Code:
    printf("%c%c%c%c%c%c%c",0x68,0x68^0xd,0x68|0x4,0x68|0x4,0x68|0xf,0x68^0x49,0x68^0x62);

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The format of an integer is determined by the machine architecture - the C standard does make quite sure that as long as some BASIC criteria is met (e.g. that there are signed and unsigned numbers [that can be either positive or negative]). There are also some minimum requirements for size/range. But how the bits are ordered and how their values are actually interpreted is up to the compiler and hardware architecture to deal with.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    isn't that the int,char will be stored in the binary of ASCII(or other type of encoding)value of that particular integer.for eg if ASCII of 1 is 49 so 1 should be internally stored as binary of 49.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by BEN10 View Post
    isn't that the int,char will be stored in the binary of ASCII(or other type of encoding)value of that particular integer.for eg if ASCII of 1 is 49 so 1 should be internally stored as binary of 49.
    No, an integer with the value of 1 will be stored as a bunch of zeros and a single 1 [in the common way that MOST processors use, at least]. If you have a char of the value '1' [in a common ASCII machine], then the value would be 49 decimal. But a char can also have the value 00000001, which is the same as the integer value 1. It also (again, in ASCII) corresponds to CTRL-A.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    i'm getting confused.the ASCII value of '1' is 49 decimal.if 1 is not getting stored as binary of 49 then what's the use of ASCII.'1' can be equally written as 49 then why ASCII codes have been made.what ASCII does at all.plz clear my confusion.
    Thanks

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by BEN10 View Post
    i'm getting confused.the ASCII value of '1' is 49 decimal.if 1 is not getting stored as binary of 49 then what's the use of ASCII.'1' can be equally written as 49 then why ASCII codes have been made.what ASCII does at all.plz clear my confusion.
    Thanks
    The TEXT CHARACTER '1' has the value 49. The number 1 as stored in an integer [and for all intents and purposes, char is a tiny integer] is not the same as '1' stored in memory. It is stored as 00000001 - the number of zeros vary depending on what size integer it is, but the binary value is always [at least for all machines I know of] a load of zeros (logically) to the left of a single 1.

    When you write int x = 1, the a value consisting of (say) 31 zeros and a single 1 will be stored in the location that represent x. If you do x = '1' then the value 49 decimal, 0000...00110001 in binary will be stored there.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Thanks again matsp.you cleared my doubt.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access Violation
    By Graham Aker in forum C Programming
    Replies: 100
    Last Post: 01-26-2009, 07:31 PM
  2. integer to binary
    By rs07 in forum C Programming
    Replies: 2
    Last Post: 09-17-2008, 12:18 AM
  3. Replies: 4
    Last Post: 08-24-2007, 05:28 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21