+ 3

Size of booleans

According to the sizeof(); table in the lesson, a boolean allocates 1 byte but since a boolean can only hold 0 or 1, wouldnt it htake up a bit?

30th Dec 2016, 5:55 AM
HDSQ.mid
HDSQ.mid - avatar
4 odpowiedzi
+ 2
In general, no data type will be a single bit because it is inconvenient to allocate and deal with less than a byte. If you are storing a lot of booleans, than you could pack up to 8 of them into a byte using something called bitfields, or even use bitwise operations to store them in integers, but you can't simply use a bit of storage by itself.
30th Dec 2016, 6:27 AM
JayDepp
JayDepp - avatar
+ 1
CPUs consider a byte as a smallest addressable unit.
12th Jan 2017, 10:55 PM
Hao Kang
Hao Kang - avatar
+ 1
Since 1 byte consists of 8 bits, 0 & 1can be written in terms of bytes like this 00000000 and 00000001 respectively.
22nd Jan 2017, 2:58 AM
nivedita
0
the "1" is for us but for the computer it is "00110001"
25th Feb 2017, 7:31 AM
Jerome Dass
Jerome Dass - avatar