I'm trying to make an int array that takes in doubles from a double array, truncates the values into ints by casting, and then using bitwise operations to get the absolute value of the ints. Here's what I've got so far:
int int_array[20];
int o;
for(o = 0; o<20; o++){
int currentNum = (int) f_array[o];
//Now use bitwise operations to get abs
int num = currentNum;
int y = currentNum >>31;
currentNum = (num ^ y) - y;
int_array[i] = currentNum;
}
I used a print statement to print out the value of y and it seems to be working (either 0 or -1), but still when I print out int_array I seem to be getting garbage values. Any ideas? Any help is appreciated, coding in C by the way.