Jump to content
The simFlight Network Forums

Recommended Posts

Posted

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

 

Posted
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 entitled
About bits, numbers and hexadecimal

Pete

 

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.