summaryrefslogtreecommitdiff
path: root/go/octal/octal.go
blob: 89b1cfc5a46747c1a356ddf1e42e20c4df41412a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package octal

import "errors"

func ParseOctal(s string) (int64, error) {
	var ret int64
	for _, v := range s {
		if v < '0' || v > '7' {
			return 0, errors.New("invalid chars")
		}
		ret *= 8
		ret += int64(v - '0')
	}
	return ret, nil
}