Skip to content

Instantly share code, notes, and snippets.

@redcap3000
Created October 28, 2011 19:51
Show Gist options
  • Save redcap3000/1323364 to your computer and use it in GitHub Desktop.
Save redcap3000/1323364 to your computer and use it in GitHub Desktop.
Number Base Conversion Helper
<?php
// Ronaldo Barbachano October 2011
// Created out of a need to compress integer values in couch databases. Php 5.3 will allow up to 36 bit bases,
// which results in the smallest integer representation.
//To convert to default base, of 8, just provide
// number_base::number_convert(1);
// encodes 1 into base 32 number
// number_base::num_convert(1,32);
// decodes base 32 number into 8
// number_base::num_convert(<base 32 number>,8,32);
class number_base{
public static function number_convert($integer,$end_base = 8,$start_base = 10){
// created to help assist in the creation of creating _id fields in couch databases
// based on integer values
return base_convert($integer, $start_base,$end_base);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment