Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static byte[] stringToHexByteArray(String string) {
        byte[] bytes = new byte[4];
        if (string != null && string.length() >= 4) {
            bytes[0] = (byte) (string.charAt(0) == '1' ? 0x01 : 0x00);
            bytes[1] = (byte) (string.charAt(1) == '1' ? 0x01 : 0x00);
            bytes[2] = (byte) (string.charAt(2) == '1' ? 0x01 : 0x00);
            bytes[3] = (byte) (string.charAt(3) == '1' ? 0x01 : 0x00);
        }
        return bytes;
    }
}