943,949 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 12741
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 17th, 2007
0

Re: Range of int

I have never seen a byte defined by anything other than 8 bits, although I don't thinnk the c or c++ standards specify its size. Here is just one of many examples.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Feb 17th, 2007
0

Re: Range of int

Click to Expand / Collapse  Quote originally posted by Narue ...
>Byte is not defined as 8 bits then what is it defined as?
It's defined as whatever the implementation wants. The standard only specifies that sizeof ( char ) be 1, and at least 8 bits. That happens to be the most common definition of a byte, but systems other than your PC also support C and don't have the same definition.
So if you had an architecture that was word addressed rather than byte addressed, it wouldn't be surprising for sizeof(char) to be 1, yet that it would be 32 bits? Or is it determined by the actual implementation of your C library?
Reputation Points: 683
Solved Threads: 53
Posting Virtuoso
Infarction is offline Offline
1,580 posts
since May 2006
Feb 17th, 2007
0

Re: Range of int

>it wouldn't be surprising for sizeof(char) to be 1, yet that it would be 32 bits?
Sure, why not?

>Or is it determined by the actual implementation of your C library?
It's determined by the compiler, not the library. Internally, a compiler will typically match the hardware for performance reasons, and the library would be written to match the compiler.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Feb 18th, 2007
0

Re: Range of int

Hi friend.
This is goutham from India.
Ur doubt is that why is char range -128 in the negative side.
The most significant bit is sign bit.
So the bits available for storing magnitude is 7.
If sign bit is 0,the number is positive and the magnitude is stored in conventional binary form.
If sign bit is 1,the number is negative and the magnitude is stored in two's complement form.
For example, +1 is stored as 00000001.
-1 is sored as 11111111.
-128 gets 10000000.

If u still cant get it reply me.
bye
Reputation Points: 11
Solved Threads: 0
Newbie Poster
goutham_see is offline Offline
7 posts
since Feb 2007
Feb 19th, 2007
0

Re: Range of int

I have never seen a byte defined by anything other than 8 bits, although I don't thinnk the c or c++ standards specify its size.
I have. They do: CHAR_BIT.
Here is just one of many examples.
I'll stick with the C and C++ definitions. 'Cuz I've been bitten where it can bite.
Last edited by Dave Sinkula; Feb 19th, 2007 at 3:15 am.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Feb 19th, 2007
0

Re: Range of int

I have. They do: CHAR_BIT
No Dave, thats a macro, actual value of that macro is defined by the compiler.

.I'll stick with the C and C++ definitions. 'Cuz I've been bitten where it can bite.
Agree. When a program must know the number of bits in a byte then use the CHAR_BIT macro.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Failing an input
Next Thread in C++ Forum Timeline: Time check problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC