Java Array From toArray(String s)

Here you can find the source of toArray(String s)

Description

to Array

License

Open Source License

Declaration

public static double[] toArray(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double[] toArray(String s) {
        double[] ret = new double[s.length() * 8];
        feedString(s, ret);/*from   w  ww.j  ava 2 s.  co  m*/
        return ret;
    }

    public static void feedString(String s, double[] networkLayer) {
        feedString(s, networkLayer, 0);
    }

    public static void feedString(String s, double[] networkLayer, int startIndex) {
        for (int i = 0; i < s.length(); i++) {
            feedChar(s.charAt(i), networkLayer, startIndex + i * 8);
        }
    }

    public static void feedChar(char c, double[] networkLayer) {
        feedChar(c, networkLayer, 0);
    }

    public static void feedChar(char c, double[] networkLayer, int startIndex) {
        int num = (int) c;
        for (int i = 0; i < 8; i++) {
            networkLayer[8 - i - 1 + startIndex] = num % 2;
            num /= 2;
        }
    }
}

Related

  1. toArray(Object... args)
  2. toArray(Object... values)
  3. toArray(String array)
  4. toArray(String emails)
  5. toArray(String number)
  6. toArray(String s)