Logo

Programming-Idioms

  • Java
  • Python
  • Go
  • Rust

Idiom #337 Convert string to integer, explicit base

Extract the integer value i from its string representation s, in radix b

import "strconv"
i, err := strconv.ParseInt(s, b, 0)
Integer i = Integer.valueOf(s, b);

Throws NumberFormatException if s is not parsable
i = int(s, b)
#include <stdlib.h>
int i = strtol(s, NULL, b);

New implementation...
< >
programming-idioms.org