From 6d5e2f019331a69132e19170e62e61f83091842a Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 6 Jul 2017 09:41:33 +1000 Subject: [PATCH] Add a lang/base38 package. --- lang/base38/base38.go | 79 +++++++++++++++++++++++++++++++ lang/base38/base38_test.go | 95 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 lang/base38/base38.go create mode 100644 lang/base38/base38_test.go diff --git a/lang/base38/base38.go b/lang/base38/base38.go new file mode 100644 index 00000000..69013318 --- /dev/null +++ b/lang/base38/base38.go @@ -0,0 +1,79 @@ +// Use of this source code is governed by a BSD-style license that can be found +// in the LICENSE file. + +// Package base38 converts a 4-byte string, each byte in [ 0-9?a-z], to a base +// 38 number. +package base38 + +const ( + // Max is the inclusive upper bound for the value returned by Encode. Its + // value equals (38*38*38*38 - 1). + Max = 2085135 + // MaxBits is the number of bits required to represent Max. It satisfies + // (1<<(MaxBits-1) <= Max) && (Max < 1< Max || got > 1<