The first step is to figure that out. tell us, in english, what it is doing. Once you can do that, writing it in Java (or any other language) is much easier.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Sep 07, 2012
Thanks for your reply.
The best I can get from looking at it (Macro) is that it is manipulating the unsigned long array using bitwise operators.
for example the unsigned long starts out as a Zero value (i.e. 0000000000000000 ) then the macro is passed in a different long array value ..... such as 0000000000000001 or 0000000000008000 along with it's corresponding 'reference number' that could be a number between 1-60). The long values are added together to make the final value 0000000000008001.
I have actually gotten this to work but by using an entirely different design approach, however, it took me several weeks to come up with the way this works. Basically I created a new class composed with Enum values with each possible value that can used such as...
public Enum enumValues
private static long VALUE_1 0000000000000001;
private static long VALUE_2 0000000000000002;
private static long VALUE_3 0000000000000004;
private static long VALUE_4 0000000000000008;
private static long VALUE_5 0000000000001000;
private static long VALUE_6 0000000000002000;
private static long VALUE_7 0000000000004000;
private static long VALUE_8 0000000000008000;
public String getNewValue(long currentValue, long refNumber)
return calculateValue(currentValue, refNumber);
private String calculateValue(long currentValue, long newValue)
// add NewValue to currentValue using packed decimal notation.
I then add the current value with any new values using packed decimal addition to get the final value.
This does work, however, I am wondering if there is a cleaner/more efficient approach to doing this.
Mike Phillips wrote:The best I can get from looking at it (Macro) is that it is manipulating the unsigned long array using bitwise operators.
This description is pretty vague. There are probably infinitely many ways to program bitwise manipulation of an array of ints in Java.
I'm not understanding the rest of your description, but I'm afraid it is a bit off. For starters, there is only one array in the expression. An item of this array is accessed using an index computed from the bit variable. And so on.
Actually, Java happens to support this kind of operation out of the box. You don't need to write a single method (let alone an enum). But before I'll tell you what it is, I'd like you to try to understand the logic on your own once more.
Mike Phillips wrote:I need to convert the following C Macro to Java. Any suggestions would be appreciated.
I guess my question would be: what does the person who's asking you to "convert" this mean by the word 'convert'?
Do they simply want you to understand what the macro is doing, or is the implementation supposed to "look" the same as the original?
Java has no equivalent of header files or macros, so the only way to make it "look" the same is to make it a method; and then you'll have to decide what it's scope should be. Should it be static? Should it be globally available?
Quite a few decisions to think about apart from just the implementation.
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here