I need to check the MSB of the following:
Another example of a posible number to be checked is 0x80000059
Test can be made with '&' operator, but how to use it depends on which data type you want to test against: your char variable is a sequence of 8-byte integers so you can test each of then for example with
DebugPrintf ("%d %d\n", J_Serial & 0x80, J_Serial & 0x80);
It will return 128 for the bytes with MSB on.
To test the (unsigned?) integer that I suppose is in your string you must first extract the value from the string and then compare it with
DebugPrintf ("%u\n", UIntVal & 0x80000000);
It will return 2147483648 if MSB is set.
Sorry but I am in deep trouble and need major help, sorry again.
I am trying to work with what Roberto has suggested but not getting very far!!
Can anyone help?
The read number is 0x8000005C which is AAA0092
The MSB is very important when set.
1000000000000000 and so it should be split as follows
1 00000 00000 00000 from which a look is used for 0 to give AAA
1 00000 00000 00011, would be AA C
1 00010 00000 00011, would be BAC etc.
How can I do this? What functions should I be using?
Thanks for your help
there is a problem in your example that must be checked before proceeding in the discussion: 0x8000005C is a 32-bit number, while you are giving examples of 16-bit numbers.
In any case, assuming you are using a 16-bit number, you can extract the relevant portion of the number as follows (supposing 'x' is the original number to elaborate):
a = (x & 0x1f); // Lowest 5 bits (0 to 4)
b = (x & 0x3e0) >> 5; // Bis 5 to 9
c = (x & 0x7c00) >> 10; // Bits 10 to 14
d = (x & 0x8000) >> 15; // MSB
each result will give a numeric value in the range 0 ÷ 31 (0x1F) from which you may start on except for the MSB which will be 0 or 1.
Thanks, I am staring to get places.
You are correct the original number is 32bits. One half, lower half, is the number, which I have been handling.
It is the upped half is the problem, which you have helped.
Up to now we always had the MSB set to 0 so it is a simple conversion along 'normal' 8 bits, 2 letters.
Now by setting the MSB we used the top bits differently to give 3 letters
Again thanks for the help