Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String HdHrIpAddressToString(int ipAddress) {
        StringBuilder theBuilder = new StringBuilder();

        byte[] theByteArray = HdHrIpAddressToByteArray(ipAddress);

        for (int i = 0; i < theByteArray.length; i++) {
            if (i == 0) {
                theBuilder.append("" + (int) (theByteArray[i] & 0xFF));
            } else {
                theBuilder.append("." + (int) (theByteArray[i] & 0xFF));
            }
        }

        return theBuilder.toString();
    }

    /**
     * The hdhr reports its IP address as an integer but the bytes and swapped compared to
     * How Android reports its integer IP addresses from the WIFI manager... thats annoying
     * @param ipAddress
     * @return
     */
    public static byte[] HdHrIpAddressToByteArray(int ipAddress) {
        byte[] theByteArray = new byte[4];

        theByteArray[3] = (byte) (ipAddress & 0xFF);
        theByteArray[2] = (byte) (ipAddress >> 8 & 0xFF);
        theByteArray[1] = (byte) (ipAddress >> 16 & 0xFF);
        theByteArray[0] = (byte) (ipAddress >> 24 & 0xFF);

        return theByteArray;
    }
}