How retrieve multiple information by a single number?

  • Context: Undergrad 
  • Thread starter Thread starter Pithikos
  • Start date Start date
  • Tags Tags
    Information Multiple
Click For Summary

Discussion Overview

The discussion revolves around the method of encoding permissions in Linux using numerical values, specifically through the chmod command, and the potential for applying similar concepts to represent combinations of items using a single number. Participants explore the implications of using binary versus decimal systems for this purpose.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant questions the algorithm behind using numbers to set permissions in Linux, noting how different combinations of numbers correspond to unique permissions.
  • Another participant explains the binary representation of permissions, detailing how each permission corresponds to a single bit and how bitwise operations can be used to check permissions.
  • A participant raises a concern about the practicality of using base 10 numbers for similar encoding, suggesting that it may not be efficient compared to binary representation.
  • Another participant agrees that using base 10 would result in a waste of numbers and emphasizes that this inefficiency is likely why binary is preferred.
  • One participant mentions that while "wasting" numbers may not be an issue when writing them down, it becomes problematic in computer applications due to the need for conversion back to binary.

Areas of Agreement / Disagreement

Participants generally agree on the efficiency of binary representation over decimal for encoding permissions and combinations, but there is no consensus on the practicality of applying these concepts in base 10.

Contextual Notes

The discussion does not resolve the potential applications of base 10 encoding or the implications of converting between number systems, leaving these points open for further exploration.

Pithikos
Messages
55
Reaction score
1
I was wondering how they did come up with the way of setting permissions using the linux program chmod by just using numbers. For example:
Code:
1 is for execute
2 is for write
4 is for read

Any sum of those give a unique permission to a file:
2+4=6 Let's you write and read it.
1+4=5 Let's you execute and read it.

So is there an algorithm behind this? Say for example that I have 5 different items and I want to be able to pass a single number and the other person to understand which combination of items I made.
 
Mathematics news on Phys.org
It becomes more apparent when you write the numbers in binary notation.
0001 is for execute
0010 is for write
0100 is for read
so each permission is indicated by a single bit.

If you want write and read, you add 0001 and 0010 and get 0011, which is 6 in decimal notation.
To check if you have write permission, you only have to check the second bit again. For a computer, that is very easy: you "AND" 0011 with the permission you want to check, e.g. 0010. If it is set, you will get 0010 back, if not, you will get 0000.
 
Thank you! That is indeed easy to grasp.
However what if we want to apply the same with base 10 numbers? Then it wouldn't be practical to write down the numbers as

0000
0001
0010
0100

Because that would yield the number 111 for just three objects. Or am I missing something?
 
Pithikos said:
Thank you! That is indeed easy to grasp.
However what if we want to apply the same with base 10 numbers? Then it wouldn't be practical to write down the numbers as

0000
0001
0010
0100

Because that would yield the number 111 for just three objects. Or am I missing something?

You are correct. You would waste lots more numbers using this technique in base 10 versus base 2. That's probably why it's not used in base 10 applications...
 
In principle, it is not a problem to "waste" so many numbers, if you are just going to write them down.

However, if you want to do this on a computer, eventually you will have to convert 11110 back to binary and you would get 11011112. So whereas you only needed 3 bits before, you now need 7 bits to store exactly the same information.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 24 ·
Replies
24
Views
3K