Java Char Array to Int charArrayDigitToInt(char[] str, int start, int len)

Here you can find the source of charArrayDigitToInt(char[] str, int start, int len)

Description

char Array Digit To Int

License

Apache License

Parameter

Parameter Description
str a parameter
start a parameter
end a parameter

Declaration

public static int charArrayDigitToInt(char[] str, int start, int len) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w w.ja v  a2  s.c o m
     * 
     * @param str
     * @param start
     * @param end
     * @return
     */
    public static int charArrayDigitToInt(char[] str, int start, int len) {
        int value = 0;
        for (int i = start; i < start + len; i++) {
            value = value * 10;
            switch (str[i]) {
            case '0':
                value += 0x00;
                break;
            case '1':
                value += 0x01;
                break;
            case '2':
                value += 0x02;
                break;
            case '3':
                value += 0x03;
                break;
            case '4':
                value += 0x04;
                break;
            case '5':
                value += 0x05;
                break;
            case '6':
                value += 0x06;
                break;
            case '7':
                value += 0x07;
                break;
            case '8':
                value += 0x08;
                break;
            case '9':
                value += 0x09;
                break;
            default:
                return value;
            }
        }
        return value;
    }
}

Related

  1. charArrayDecimalToInt(char[] str, int start, int len, int mul)
  2. charArrayHexToInt(char[] str, int start, int len)
  3. charArrayToInt(char[] data, int start, int length, int[] end)
  4. charsToInt(char[] chars, int offset)