Data Types

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 20
Reputation: Drake is an unknown quantity at this point 
Solved Threads: 0
Drake's Avatar
Drake Drake is offline Offline
Newbie Poster

Data Types

 
0
  #1
Apr 24th, 2008
Data types are used to represent numbers and characters used in a program, why do programmers benifit from having such a variety? Also if anyone could help me out with what an unsigned character is used for?

thanks for the help
Last edited by Drake; Apr 24th, 2008 at 5:57 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: Data Types

 
0
  #2
Apr 24th, 2008
Tipically a char is 8-bit long, and most significant bit(MSB) represent the sign value.
If MSB is 0, it means positive and if MSB is 1, it means negative.

So only last 7 bits (out of 8 bits) are used to store the actule char value. And total number of values will be 2^7 = 128 (0 to 127) or (-128 to 0).
But when we declare a char as unsigned then there is no importance of the sign bit (i.e MSB), So now total value stored in char will be 2^8 = 256 (0 to 255), and this will cover all the char values.

One of important use of unsigned char is in embedded system, to store the value of some 8-bit register.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,728
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: 737
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Data Types

 
1
  #3
Apr 24th, 2008
>why do programmers benifit from having such a variety?
They can choose the data type that best fits the problem and optimize speed or storage costs.

>Also if anyone could help me out with what an unsigned character is used for?
Off the top of my head: If you don't want negative numbers, if you want to extend the range of signed char but don't want to jump up to short int, if you need the wrap-around qualities of an unsigned type, if you want to store an object in an array of bytes (unsigned char is the only type guaranteed not to have padding bits).
I'm here to prove you wrong.
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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC