سؤال

In learncpp I noticed that it says that 2 bits can store 4 different values and they give an example in the table. I am somewhat confused by what they mean. My original interpretation was that 2 bits can only store 2 values (ie. just 0 and 1 since the definition of a binary digit is 0 or 1). However after looking at the table, do they mean that two bits can store 4 different COMBINATIONS of values (ie. 00 01 10 11).

هل كانت مفيدة؟

المحلول

do they mean that two bits can store 4 different COMBINATIONS of values (ie. 00 01 10 11).

Yes. Each unique "combination" (actually they are permutations) of bits represents a different value.

This is no different to the system of counting you are used to: the decimal system, except instead of each digit having two possible states (0 and 1) they have ten possible states (0, 1, ..., 8, 9). In binary (base 2), two digits can represent four different values (2 ^ 2), and in decimal (base 10), two digits can represent 100 different values (10 ^ 2).

نصائح أخرى

They mean exactly that: Two bits store the values 0, 1, 2, and 3, which have a binary encoding of 00, 01, 10, and 11, respectively.

To work out the number of permutations you can do base^length and 2^2 is 4. There are 4 permutations possible in 2 bits.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top