Next Changeset →

Changeset 103:3d29e6c1ac92 in iovar


Ignore:
Timestamp:
Sep 11, 2017, 2:10:34 PM (4 months ago)
Author:
Shawn Wilson <shawn@…>
Branch:
default
Phase:
public
Tags:
tip
Message:

saw_091117_1 - Add Utils.hexToBytes().

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r102 r103  
    22Copyright (C) 2011-2015 Lannocc Technologies
    33@%@~LICENSE~@%@
     4
     5saw_091117_1 - Add Utils.hexToBytes().
    46
    57saw_091017_1 - Add Utils.bytesToHex().
  • src/win/iovar/web/Utils.java

    r102 r103  
    11/*
    2  * Copyright (C) 2016 Virgo Venture, Inc.
     2 * Copyright (C) 2016-2017 Virgo Venture, Inc.
    33 * Copyright (C) 2011-2014 Lannocc Technologies
    44 * @%@~LICENSE~@%@
     
    417417        return hexString.toString ();
    418418    }
     419   
     420    public static byte[] hexToBytes (final String hex)
     421    {
     422        final int len = hex.length ();
     423        final byte[] bytes = new byte[len / 2];
     424       
     425        for (int i=0; i < len; i+=2)
     426        {
     427            bytes[i/2] = (byte) ((Character.digit (hex.charAt (i), 16) << 4)
     428                    + Character.digit (hex.charAt (i+1), 16));
     429        }
     430       
     431        return bytes;
     432    }
     433   
     434    /**
     435     * For testing
     436     */
     437    public static void main (final String[] args) throws Exception
     438    {
     439        String hex = bytesToHex ("just a test".getBytes ());
     440        byte[] bytes = hexToBytes (hex);
     441       
     442        System.out.println (new String (bytes));
     443    }
    419444}
Note: See TracChangeset for help on using the changeset viewer.