C ++ - 3 possible values ​​in a variable?

I need to save a combination of 30 letters, but each letter can only be "0", "1" or "2". When I use sizeof (myString), it returns 32.

I want to use this 30 letter combination to access an array string, so I wonder if it is possible to use 3 bool values ​​of any type to store 1 out of 3 values.

+3
source share
3 answers

3 ^ 30 = 205891132094649 (~ 2E14), which is less than the maximum value of a 64-bit integer (~ 2E19), so you can match strings with 64-bit ints 1: 1.

-3, . 4, ( /), , 4 ^ 30 2 ^ 64.

+12

C ++ ( , ) - char. bool char, . , - . - , .

+2

Boost tri-bool 3- , . 2- , 64 , .

0

Source: https://habr.com/ru/post/1747688/


All Articles