Current location: Hot Scripts Forums » Programming Languages » C/C++ » bit and byte question


bit and byte question

Reply
  #1 (permalink)  
Old 12-26-06, 03:11 PM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
bit and byte question

Charachter x in binary is: 01111000. This charachter use 7 bit: 1111000. right ?

This page: http://neonatus.net/C/ch03/ch03.htm write, the charachter x require 1 byte.
But I don't understand why number 500 is 2 byte. Someone explain this thing for me ?

I know 4 bit is a nibble and 8 bit is 1 byte.
Reply With Quote
  #2 (permalink)  
Old 12-27-06, 05:09 PM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by zoliky
Charachter x in binary is: 01111000. This charachter use 7 bit: 1111000. right ?
01111000 is 8 bits
1111000 is 7 bits

When using c and c++ the size of each type is dependant upon your machine, but a char is normally 8 bits
Quote:
This page: http://neonatus.net/C/ch03/ch03.htm write, the charachter x require 1 byte.
and that's correct. 8 bits = a byte

Quote:
But I don't understand why number 500 is 2 byte. Someone explain this thing for me ?
It depends on the datatype. An int is 32 bits and a short int is 16 bits or two bytes. More bits = more storage space. A short int (2 bytes) storing the number 500 has more storage space than a char (8 bits) storing x.

Simply put, numeric types are larger and have more storage space than chars. A char is a single character and can't hold the number 500.
__________________
my site
Reply With Quote
  #3 (permalink)  
Old 12-28-06, 05:31 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
thanks
Reply With Quote
  #4 (permalink)  
Old 01-14-07, 05:26 PM
balkman balkman is offline
New Member
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
if you take a look at the ascii table, all characters are represented as decimal numbers as well. These numbers only go up to 256, which is exactly what 8-bits is able to hold (0-255).

Any integer value that is greater than 255, must have more than 8 bits to represent it.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 04:38 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.