Java ASCII from toAsciiByteArray(final char[] carr)

Here you can find the source of toAsciiByteArray(final char[] carr)

Description

to Ascii Byte Array

License

Open Source License

Declaration

public static byte[] toAsciiByteArray(final char[] carr) 

Method Source Code

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

public class Main {
    public static byte[] toAsciiByteArray(final char[] carr) {
        final byte[] barr = new byte[carr.length];
        for (int i = 0; i < carr.length; ++i) {
            barr[i] = (byte) ((carr[i] <= '\u00ff') ? carr[i] : '?');
        }/*from  ww w .  j  a v  a  2  s.c  o m*/
        return barr;
    }

    public static byte[] toAsciiByteArray(final CharSequence charSequence) {
        final byte[] barr = new byte[charSequence.length()];
        for (int i = 0; i < barr.length; ++i) {
            final char c = charSequence.charAt(i);
            barr[i] = (byte) ((c <= '\u00ff') ? c : '?');
        }
        return barr;
    }
}

Related

  1. toAscii(String s)
  2. toASCII(String s)
  3. toAscii(String s)
  4. toASCII(String str)
  5. toAsciiArray(char[] carr)
  6. toAsciiByteArray(String s)
  7. toAsciiBytes(final String value)
  8. toAsciiBytes(String str)
  9. toAsciiChar(byte b)