Class: B62

Inherits:
Object
  • Object
show all
Defined in:
ext/b62/b62.c

Class Method Summary collapse

Class Method Details

.to_b62(arg) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'ext/b62/b62.c', line 17

static VALUE encode(VALUE self, VALUE arg)
{
  u_int64_t input = NUM2ULL(arg);
  char output[12];
  unsigned short i = 11;

  output[i] = '\0';

  do
  { 
    output[--i] = b62_table[input % 62]; 
  }
  while((input = input / 62) > 0);

  return rb_str_new2(&output[i]);
}