• Post Reply Bookmark Topic Watch Topic
  • New Topic

Boolean - why it takes 8 bits to store a bit  RSS feed

 
ajit a
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all ...
can someone tell me why is it that java takes 8 bits to store a bit( 0 or 1) in case of boolean.
thx in advance..
@jit.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I guess it can take up to 4 bytes (int) to store value. It uses the int data type to store true or false (1 0r 0 ) becoz there are machine instructions for integers and not for boolean.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, a boolean takes one byte while an int takes 4 bytes.
It isn't possible to store data on disk in units of less than one byte (8 bits).
 
ajit a
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron ..
Thx for replying, but has it anyything to do with how processor processes the data, or its just coz we cant store anything less than a byte.
..Ajit
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ajit,
You guessed it right. Actually the processor always does calculations on bytes(takung 8 bits together), not on each single bit(for speedy calculations), therefore it should be now obvious that we can't have a size specified less than 1 byte.
 
ajit a
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx Anirban dutta
 
ajit a
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oho .. sorry Anirban, actually i wanted to pick up this smiley ... neway i guess that doesnt matter much .. thx a lot ... ajit
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ajit,
It's all right, guy. you seem to be a smiley master.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!