Abdullah Radwan Posted May 18, 2019 Report Posted May 18, 2019 Hi, I am using C++ SDK. I am not familiar with bits system. I want to read radio audio switches (offset 3122). Could somebody provide an example? I want to check which com is selected.
Abdullah Radwan Posted May 25, 2019 Author Report Posted May 25, 2019 After playing a lot, here is working code: byte audioSelection; FSUIPC_Read(0x3122, 1, &audioSelection, &error); int comSelection = 0; if(audioSelection >= 128) comSelection = 1; //Com 1 else comSelection = 2; //Com 2
Pete Dowson Posted May 25, 2019 Report Posted May 25, 2019 1 hour ago, Abdullah Radwan said: After playing a lot, here is working code: Well done. But in general, when you want to test one "bit" in a byte, you'd use: if (x & mask) ... where x is the value you've read, and "mask" is the value of the bit( you want to test for. So in your case: if (audioSelection & 128) for COM1, and if (audioSelection & 64) for COM2 There are other bits for the other audio switches. Bit values are derived from evaluation 2 to the power n, i.e. 2 times 2 'n' number of times, with the special-seeming case that 0 results always in the value 1. So: bit 0 = 1 bit 1 = 2 bit 2 = 4 bit 3 = 8 bit 4 = 16 bit 5 = 32 bit 6 = 64 bit 7 = 128 For more about bits, see the FAQ subforum help thread entitledAbout bits, numbers and hexadecimal Pete 1
Abdullah Radwan Posted May 26, 2019 Author Report Posted May 26, 2019 Thank you so much! This what I need. Thanks for pointing out the correct way.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now