This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.
Last Updated: 2024-11-23
What is the advantage?
st_mode
(stat data type) of 33188
in decimal to 0100644
in octal. Given that we know the last 9 bits in octal are the permission bits, we can read off the permissions as 644
re conversion:
just replace the octdigits with 3 bits binary strings (0=000, 1=001, 2=010, 3=011, 4=100, 5=101, 6=110, 7=111) and finally remove all leading zeros to the left and when you do binary to octal just add no to 2 zeros to the left until the length is divisible by 3 and than translate block of 3 bits.
How to know when a number is represented as such?
0
- e.g. instead of let x = 52;
you have let x = 052;
. The
leading 0 is informative since it is always superfluous.