From: David McGlone on
Hi again

I'm trying to learn about octal numbers and I don't understand this:

Binary: 001000101111
breakdown: (001)= 1 (000)= 0 (101)=5 (111)=7

I know it's similar to unix permissions, but I'm not understanding where for
example: 111 = 7

wikipedia has got me all confused.

--
Blessings,
David M.
From: Stephen on
On 10-06-30 10:02 PM, David McGlone wrote:
> Hi again
>
> I'm trying to learn about octal numbers and I don't understand this:
>
> Binary: 001000101111
> breakdown: (001)= 1 (000)= 0 (101)=5 (111)=7
>
> I know it's similar to unix permissions, but I'm not understanding where for
> example: 111 = 7
>
In base 10, which you use every day, we go
0
1
2
3
4
5
6
7
8
9
10

The number 10 is the number of distinct digits we use.

In binary we only us two, 0 and 1, so 10 is 2 decimal

So we go

0 = 0 decimal
1 = 1 << important
10 = 2 << important
11 = 3
100 = 4 << important
101 = 5
110 = 6
111 = 7

So binary 111 is 4 + 2 + 1 = 7

Stephen
From: Shreyas Agasthya on
It would also mean that 7 (8 digits which includes 0) is the highest numeric
representation that you can have or go up to in an octal representation.

So to take your example and represent an octal number :

001000101111 (subscript 2) = 1057(subscript 8)

--Shreyas

On Thu, Jul 1, 2010 at 7:42 AM, Stephen <stephen-d(a)rogers.com> wrote:

> On 10-06-30 10:02 PM, David McGlone wrote:
>
>> Hi again
>>
>> I'm trying to learn about octal numbers and I don't understand this:
>>
>> Binary: 001000101111
>> breakdown: (001)= 1 (000)= 0 (101)=5 (111)=7
>>
>> I know it's similar to unix permissions, but I'm not understanding where
>> for
>> example: 111 = 7
>>
>>
> In base 10, which you use every day, we go
> 0
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
>
> The number 10 is the number of distinct digits we use.
>
> In binary we only us two, 0 and 1, so 10 is 2 decimal
>
> So we go
>
> 0 = 0 decimal
> 1 = 1 << important
> 10 = 2 << important
> 11 = 3
> 100 = 4 << important
> 101 = 5
> 110 = 6
> 111 = 7
>
> So binary 111 is 4 + 2 + 1 = 7
>
> Stephen
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Regards,
Shreyas Agasthya
From: tedd on
At 10:02 PM -0400 6/30/10, David McGlone wrote:
>Hi again
>
>I'm trying to learn about octal numbers and I don't understand this:
>
>Binary: 001000101111
>breakdown: (001)= 1 (000)= 0 (101)=5 (111)=7
>
>I know it's similar to unix permissions, but I'm not understanding where for
>example: 111 = 7
>
>wikipedia has got me all confused.
>
>--
>Blessings,
>David M.

David:

You're mixing things (Octal/Permissions)-- let's deal with Octal first.

All number systems have a defined base for the power of their
placeholder. Our Decimal system is based upon tens. More explicitly
-- each placeholder in the Decimal system is dependant on a power of
ten. For example, the number 559 (DEC) is simply:

(5 x 10^2) + (5 x 10^1) + (9 x 10^0)

That's 5 times 10 to the power of two, plus 5 times 10 to the power
of 1, plus 9 times ten to the power of zero (which is always 1). The
sum of the products is 559.

I won't go into the reasons why we want to convert numbers between
bases, but there are reasons.

The beauty of Octal (base 8) is it is much easier to convert from
Binary than it is to convert Binary to Decimal. Additionally, it's
simpler to convert Octal to Decimal than it is to convert Binary to
Decimal, Lastly, it is much easier to take the conversion from Binary
to Octal and then convert from Octal to Decimal in a two step process
than it is to it all at once by converting Binary to Decimal. That's
the main reason why we use Octal.

For example:

If you take the Binary number:

001000101111 (BIN)

and translate that to Octal, you have:

1057 (OCT)

How did I do that? That is (as you said above) a very easy process --
you just break it up into groups of three.

(100) = 1, (000) = 0, (101) = 5, (111) = 7

But what you are actually doing is:

1 x 10^3 (OCT) + 0 x 10^2 (OCT) + 5 x 10^1 (OCT) + 7 x 1 x 10^0( OCT)

-- side note --
Why is 111 = 7? It's because:

1 x 10^2 = 4
1 x 10^1 = 2
1 x 10^0 = 1

Total 7 -- Interestingly enough it's 7 in both Octal and Decimal (and
anything greater than base 8).
-- end of side note ---

But realize the number 10 in Octal is 8 in Decimal. As such, I can
convert Octal to Decimal pretty easily by:

1 x 8^3 = 512
0 x 8^2 = 0
5 x 8^1 = 40
7 x 8^0 = 7

559 (DEC)

Please note 4 computations.

Whereas, if I tried to convert Binary (base 2) directly to Decimal
(based 10) it would go like this:

0010 0010 1111 (BIN)

1 x 10^9 = 512
0 x 10^8 = 0
0 x 10^7 = 0
0 x 10^6 = 0
1 x 10^5 = 32
0 x 10^4 = 0
1 x 10^3 = 8
1 x 10^2 = 4
1 x 10^1 = 2
1 x 10^0 = 1

Total: 559

Please note 10 computations!

As you can see above, it is *much* easier to take a Binary number and
break it into Octal portions by simply looking at the pairs of three,
namely:

(100) = 1, (000) = 0, (101) = 5, (111) = 7

And from that run the Octal to Decimal conversion.

=== Now permissions ===

Permissions are set to the power of 8 (Octal). Why? Because we don't
need a higher base number system to cover the needs of setting
permissions. It is defined as:

read (r) = 4
write (w) = 2
execute (x) = 1

So, the numbers mean:
7 = rwx (read write execute)
6 = rw- (read and write)
5 = r-x (read and execute)
4 = r-- (read)
3 = -wx (write and execute)
2 = -w- (write)
1 = --x (execute
0 = --- (no access)

The permission system for files/directories is divided into
divisions, namely "Owner", "Group", and "ALL". Each division can have
their own permission settings. The standard is to list them in order
of "Owner", "Group", and "ALL" such as:

777 means that all three divisions have their permission set to read,
write, and execute.
755 means that the Owner has permission set to read, write, and
execute whereas the "Group", and "ALL" have their permissions set to
only read and execute.

You often see this displayed as:

Owner Group All example --- chmod 777
rwx rwx rwx rwx rwx rwx

Owner Group All example --- chmod 755
rwx r-x r-x rwx r-x -r-x

Owner Group All example --- chmod 766
rwx rw- rw- rwx rw- rw-

Owner Group All example --- chmod 644
rw- r-- r-- rw- r-- -r--

Owner Group All example --- chmod 600
rw- --- --- rw- --- ---

There is no magical rule why we use Octal for this. In fact, we could
have used any system greater than base 8 -- even base 16 (HEX), but
there was no need for more (there is, but I don't want to explain
that).

I hope this lifts some of the confusion.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com