26.12.2011, 12:50
I write a plugin that has a 'chmod' function, in C/C++ using the octal number like 0777 0644 etc.
if i say, that people must use 1 2 4 8 16 (1 | 2 | 4) etc. it would be strange, would prefer to use the 0777 0644 etc.
000 = 0
010 = 8
020 = 16
030 = 24 (010 + 020)
040 = 32
050 = 40 (010 + 040)
060 = 48 (040 + 020)
070 = 56 (010 + 020 + 040)
like using 1 2 4 8 16 32 64 128 256 512 1024 etc.
//EDIT:
is there any easier way?
if i say, that people must use 1 2 4 8 16 (1 | 2 | 4) etc. it would be strange, would prefer to use the 0777 0644 etc.
000 = 0
010 = 8
020 = 16
030 = 24 (010 + 020)
040 = 32
050 = 40 (010 + 040)
060 = 48 (040 + 020)
070 = 56 (010 + 020 + 040)
like using 1 2 4 8 16 32 64 128 256 512 1024 etc.
//EDIT:
pawn Код:
stock OctalValue(x)
{
new str[10], rn;
valstr(str, x);
for(new z, i = strlen(str) - 1; i >= 0; i--, z++)
rn += (str[i] - '0') * floatround(floatpower(8.0, z));
return rn;
}