开发者

How do I find permutations or combinations for byte?

A character (1 byte) can represent 255 characters but how do i a开发者_运维技巧ctually find it?


(answering the comment)
There are 256 different combinations of 8 0s and 1s.

This is true because 256 = 28.
Each digit that you add doubles the number of combinations.


In a fixed width binary number, there are two choices for the first bit, two choices for the second bit, two choices for the third, and so on. The total number of combinations for an 8-bit byte is:

2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 28 = 256


do you mean

for (char c = " "; c <= "~"; c++) std::cout << c << std::endl;

?

This should show you printable characters in ASCII proper. To see all characters in your font, try c = 0 and c < 255 (be careful with 255 and infinite loop) - but this won't work with your terminal, most probably.


8 bits can represent permutations of ones and zeros from binary 00000000 to 11111111. Just like 3 decimal digits can represent permutations of decimal numbers (0-9) from decimal 000 to 999.

You just start counting: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and then after you reach the digit maximum, you carry over a 1 and start from 0: ..., 8, 9, 10. Right? And then continue this until you fill up all your digits with nines: ..., 997, 998, 999.

It's the same thing in binary: 0, 1 then carry over 1 and start from 0: 0, 1, 10. Continue: 10, 11, 100, 101, 110, 111, 1000, 1001 etc.

Simply counting from 0 to the maximum value than can be represented by your digits gives you all the permutations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜