Publishing my sensor values in binary from decimal

asked 2017-03-15 22:08:08 -0500

Hello,

I have values coming into my system from four sensors through serial communication. If high I should get a 1 and if low its 0, which indicates which sensors are engaged and which aren't. e.g. sensor 1 (true) sensor 2,3,4 (false) , so value should be 1000.

This is my printing statement:

ROS_INFO_THROTTLE(1, "Received raw data: %d", sensor_val); (using C++)

However, I am getting decimal values (obviously as I am doing %d).

I wrote my simple binary function:

void binary(int num){
int rem;
if (num <= 1){
    cout << num;
    return;
}
rem = num % 2;
binary(num / 2);
cout << rem;
}

But when i do binary(sensor_value) it throws me warning and it still continues to print decimal values. So write now for the same scenario I am getting 8 instead of 1000. This is a simple printing problem, but could someone please help me out with this.

Thanks appreciate your time and help in advance.

edit retag flag offensive close merge delete