Is it faster to access the byte than a bit? What for?

The question is very direct: is it faster to access the byte? If I store 8 booleans in a byte, will it be slower if I have to compare them than if I used 8 bytes? Why?

+5
source share
6 answers

Probably not. The smallest addressable memory unit on most machines today is bytes. In most cases, you cannot access a bit or access it.

In fact, accessing a specific bit can be even more expensive because you need to create a mask and use some logic.

EDIT:

"", , . , , .

: ( ), - . , bools, , .

+4

, , ( ) . , , , , , . , - .

+2

- 8- . , , . , bools , .

, . , , , , .

+1

, , ( ), , , , , .

, , .NET system.collections.bitarray, 32- . , ( , 32- ), , .

, , . , , :

bool a0, a1, a2, a3, a4, a5, a6, a7;

( ):

if ( a0 && a1 && !a2 && a3 && !a4 && (!a5 || a6) || a7) {
...
}

, (, , ) . , , .

, , , ( , , , ).

, .NET system.collections.bitarray.

+1

, 32- , , "bool" "byte". , , , ... , . , .

+1

Computers tend to refer to things in words. Access to bits is slower because more effort is required:

Imagine that I said something to you, and then said: "Oh, replace your second word instead." Now imagine that my editing was "oh, change the third letter in the second word."

Which requires more thought on your part?

0
source

All Articles