Range of int

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 15,605
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1490
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Range of int

 
0
  #11
Feb 17th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Range of int

 
0
  #12
Feb 17th, 2007
Originally Posted by Narue View Post
>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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 750
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Range of int

 
0
  #13
Feb 17th, 2007
>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.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 7
Reputation: goutham_see is an unknown quantity at this point 
Solved Threads: 0
goutham_see goutham_see is offline Offline
Newbie Poster

Re: Range of int

 
0
  #14
Feb 18th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,444
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Range of int

 
0
  #15
Feb 19th, 2007
Originally Posted by Ancient Dragon View Post
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.
Originally Posted by Ancient Dragon View Post
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,605
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1490
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Range of int

 
0
  #16
Feb 19th, 2007
Originally Posted by Dave Sinkula View Post
I have. They do: CHAR_BIT
No Dave, thats a macro, actual value of that macro is defined by the compiler.

Originally Posted by Dave Sinkula View Post
.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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC