Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-11-2008, 10:03 AM
bodhi2016 bodhi2016 is offline
Newbie
 
Join Date: Jan 2008
Posts: 29
Rep Power: 4
bodhi2016 is on a distinguished road
Default Range Of Char Variable

I have been pondering upon this question for quite a long time
In a c++ programmingbook i saw that it was written that
range of char is from -128 to 127{127-(-128)=256}.
Please can anybody tell me the meaning of this in details.
I knew that a char variable has a size of
1 byte which is equal to 8 bits.Since in 8 bits the max.
can be number can be 11111111 which is equal to 1x2^7+1x2^6.....
and so on .but 2^7 is equal to 128 and and 2^8 is 256.
I realised that this "Range" has something to do
with this .Plzzzzzzzz i would like someone to explain
this in details.Same with the case of an ip
address. Each number has to be between 0 and 256
But in char we used to write char='a'.
Does this "range" correspond to the ASCII value of a.
Plzz somebody somebodyn explain.
Thank You
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-11-2008, 12:10 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,421
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: Range Of Char Variable

First, char does not necessarily have that range. It is platform/compiler dependent, and has that range as a minimum. Also, char is not necessarily signed.

8 bits gives you a range of 00000000 = 0 to 11111111 = 255. If the high bit is the sign bit, your range is 00000000 = 0 to 01111111 = 127 and 10000000 = -128 to 11111111 = -1
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-12-2008, 05:59 PM
dcs dcs is offline
Programming Expert
 
Join Date: Mar 2008
Posts: 371
Rep Power: 6
dcs has a spectacular aura aboutdcs has a spectacular aura about
Default Re: Range Of Char Variable

The range of char is from CHAR_MIN to CHAR_MAX. The number of bits in a byte (I'm using it interchangeably with char) is CHAR_BIT. These values are found in <limits.h>/<climits>.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
char * and char[] problem Anirban Chakraborty C and C++ 5 11-30-2007 09:32 AM
a little problem with char array worried_student C and C++ 2 11-23-2007 11:18 AM
Works when i have an int NoName C and C++ 1 08-28-2007 12:25 AM
Java:Tutorial - The Variable John Java Tutorials 0 12-09-2006 10:59 AM


All times are GMT -5. The time now is 11:42 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads