Question: I have two C modules that each use some functionality of the other. In my makefile I have expressed this thus:

```
moduleA.h: common.h moduleB.h
moduleB.h: common.h moduleA.h

```

For obvious reasons this generates a circular reference warning though it goes on to compile fine. What is the correct way of resolving this? Should I refactor the modules to create a third - moduleC - that ties the two together?

Module A is a logging module and module B is a cronjob implementation. Logging uses cronjob to schedule log rotates and cronjob uses logging to tell everyone what it's up to.

Module C would be rather small; simply create a cronjob to call a logging rotate function but logging would then not need to know about cronjob. Cronjob would still depend on logging of course.

Or should I just ignore the warning?

Answer: 
If it helps at all, here's a class that I made that converts longs to binary Strings and binary Strings to longs:

```
public class toBinary {

    public static void main(String[] args) {
        System.out.println(decimalToBinary(16317));
        System.out.println(binaryToDecimal("11111111111111111111111111111111111100101001"));
    }

    public static long binaryToDecimal(String bin) {
        long result = 0;
        int len = bin.length();
        for(int i = 0; i < len; i++) {
            result += Integer.parseInt(bin.charAt(i) +  "") * Math.pow(2, len - i - 1);
        }
        return result;
    }

    public static String decimalToBinary(long num) {
        String result = "";
        while(true) {
            result += num % 2;
            if(num < 2)
                break;
            num = num / 2;
        }
        for(int i = result.length(); i < 32; i++)
            result += "0";
        result = reverse(result);
        result = toLittleEndian(result);
        return result;
    }

    public static String toLittleEndian(String str) {
        String result = "";
        result += str.substring(24);
        result += str.substring(16, 24);
        result += str.substring(8, 16);
        result += str.substring(0, 8);
        return result;
    }

    public static String reverse(String str) {
        String result = "";
        for(int i = str.length() - 1; i >= 0; i--)
            result += str.charAt(i);
        return result;
    }

}

```

It doesn't take decimal values, but it could probably give you a bit of guidance.
The conversion is trivial once you know what the endianess means on binary level. The question is more what do you really want to do with it?

```
public static int flipEndianess(int i) {
    return (i >>> 24)          | // shift byte 3 to byte 0
           ((i >> 8) & 0xFF00) | // shift byte 2 to byte 1
           (i << 24)           | // shift byte 0 to byte 3
           ((i & 0xFF00) << 8);  // shift byte 1 to byte 2
}

```

This little method will swap around the bytes in an int to switch between little/big endian order (the conversion is symetric). Now you have a little endian int. But what would you do with that in Java?

More likely you need to write the data to a stream or something, then its only a question in which order you write the bytes out:

```
// write int to stream so bytes are little endian in the stream
// OutputStream out = ... 
out.write(i);
out.write(i >> 8);
out.write(i >> 16);
out.write(i >> 24);

```

(For big endian you would just order the lines from bottom to top...)