Get multiple information on one number?

I was wondering how they came up with a way to set permissions using chmod, just using numbers. For instance:

1 is for execute
2 is for write
4 is for read

Any sum of them gives a unique permission:

2+4   = 6 lets you write and read.
1+4   = 5 lets you execute and read
1+2+4 = 7 lets you execute, read and write

Is there an algorithm? Say, for example, I have 10 items, and I want to give a person a number and just a number that a person can determine which items I have selected.

+5
source share
1 answer

. 1, 2, 4, 8, 16 0--1- . 2^0=1, 2^1=2, 2^2=4, 2^3=8 ..

(read/ex/write) .

( ) : (.. ), , . , . 10.

+4

All Articles