From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-08-2017 08:33 AM - edited 11-08-2017 08:38 AM
@lavid2002 wrote:
Morning Everyone,
I need to convert a 19 bit binary string into 1's compliment. (I think that's the right nomenclature?)
E.G. I need 1111111110000000010
To become 0000000001111111101
I have added a picture of my code.
For those curious. I am processing 32 bit ARINC-429 format words from avionics. Specifically, I am using case structures for the temperature and pressure altitude words. The sign bit is the 19th bit, and the data switches the 0s to 1s and 1s to 0s. I need to reverse this so I can convert it into my new negative engineering unit.
Thanks everyone!
Just using AND with 0x7FFFF mask will only work with positive numbers. The original post by the OP said the 19th bit was the sign bit, so I am assuming the result could be negative. You need to extent the sign bit (19th bit) to the rest of the upper 13 bits that you zero'd out. Here is what it would look like
11-08-2017 10:50 AM
Close, but it's not quite working yet.
I'm already using a case structure to identify the sign bit (19th bit)
The order that the data is displayed is as follows
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
My problem was the NOT gate was adding 13 additional bits (to get us to 32 bits) to the right of the data. Let's display these as negative numbers. So I am left with
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
The AND gate is truncating my data back down to 19 bits, but it's taking the bits off the left , and leaving me with this
7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
How can I get this AND gate to only trim from the right side?
Here are a couple screen shots 🙂
11-08-2017 11:27 AM
Did you try my VI ?
11-08-2017 11:30 AM
@lavid2002 wrote:
Close, but it's not quite working yet.
I'm already using a case structure to identify the sign bit (19th bit)
The order that the data is displayed is as follows
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
My problem was the NOT gate was adding 13 additional bits (to get us to 32 bits) to the right of the data. Let's display these as negative numbers. So I am left with
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
The AND gate is truncating my data back down to 19 bits, but it's taking the bits off the left , and leaving me with this
7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
How can I get this AND gate to only trim from the right side?
Here are a couple screen shots 🙂
I was assuming bit 0 is the least significant bit. You said the sign bit was the 19th bit, so you needed the bottom 19 bits. I have never seen a bit pattern numbering system starting at LSB -12, skipping 0, and ending the MSB at +19.
If 0x0007FFF is the mask for the bottom 19 bits, can't you figure out what the mask for the top 19 bit mask would be? If you can't do it with a hex number, try it with binary.
Bottom 19 bits mask is:
0x0007FFF = 0b00000000000001111111111111111111 (that's 13 zeros followed by 19 ones)
Top 19 bits mask is?? ( Try it yourself before you click the spoiler for the answer)
11-08-2017 11:35 AM
The Truncated Inverted is only showing the 9 LSbs since those are the 1s (by default does not show any preceding 0s). If you change your display format of that indicator, you should see the value you are looking for.
But your string conversions make no sense to me. Why convert a number to a string and then just back to a number? Just wire your Truncated Inverted number to the multiplication.
11-08-2017 12:15 PM
@lavid2002 wrote:
Close, but it's not quite working yet.
I'm already using a case structure to identify the sign bit (19th bit)
The order that the data is displayed is as follows
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
My problem was the NOT gate was adding 13 additional bits (to get us to 32 bits) to the right of the data. Let's display these as negative numbers. So I am left with
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
The AND gate is truncating my data back down to 19 bits, but it's taking the bits off the left , and leaving me with this
7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
How can I get this AND gate to only trim from the right side?
Here are a couple screen shots 🙂
Hard to figure out what is going on with your code with a screen shot. And I am really confused!!!
The data going to case "211" is U32 (because the "OAT" indicator is U32 with no coercion dot). I pulled this out of picture and this is how you determine the "SIGN" from the 19th bit of the data. The "Array Subset" index also counts from right to left !!! Is this what you intended?
According to your numbering scheme, the sign bit (counting right to left) is "7" (marked in red). And your data you want is "19,18,....,2,1" (marked in blue). So is "7" the sign bit or is it part of the data? I can't help you unless you define what the data format really is. Otherwise I am just guessing.
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12
11-08-2017 01:05 PM
OK This is my last guess. If the data are in the most significant 19 bytes, the sign bit should be bit 31 by default. The bottom 13 bits are not needed and should be zero'ed out.
That is the number that you ultimately want, but shifted 13 bits to the left. Thus, the value is 2^13 to large. You could either shift it right 13 bits or divide the value by 2^13. Dividing by 2^13 is the same as multiplying by 0.0001220703125. Guess what, that is the exact multiplier you have in the case statement. So, I think I am close to the solution. Try this code.
i.e. instead of adding a "-1", you can use the "decrement" function
BTW what is the value you are expecting to get with 1111111110000000010
11-08-2017 02:25 PM
First off, let me say this if my first post on this forum, and it's awesome the quality of the responses I'm getting here, and how quickly you guys jump on the questions. I really appreciate all the help.
I've realized I did a poor job of explaining my requirements for the code. I noticed that just inverting the string, and trimming the extra 13 bits doesn't really get me where I need to be. To fix that, let me explain my objective clearer.
The data is coming over in ARINC 429 format. This is a 32 bit format. However the VI I am using gives me the 19 bit "Data" section, of the 32 bit word in 19 bits. I have made a small table to relate Decimal to Binary. See "DecimalandBinaryExamples"
Here's what I think needs to happen.
1)I need to invert the string
2)I need to get rid of the additional 13 bits that are added
3)I need to get rid of the 9 padding zeros on the right of the word that have been turned into 1s by my NOT gate.
4)I need to apply my binary multiplier (Which should only be 1, but since I have all of these zeros remaining that I don't know how to get rid of, I have just found the constant that gives me the numbers I am looking for)
5)I need to subtract 1
I'll update this VI to have the decrement function instead of adding -1.
Can you guys think of a better way to do this? This currently works, so I'm ok with moving forward with this.
The idea to use 2 simple gates to identify my sign bit is much much more efficient, I'm applying this to both portions of my code that deal with negative numbers (Pressure altitude and Outside Air Temperature).
I've also attached a screen shot of my VI that is yielding appropriate numbers (NegativeOAT429)
11-08-2017 03:47 PM
I finally googled ARINC 429. I looked at the Wikipedia page here and this is the word format that I found.
courtesy of Wikipedia
According to this, the data is located in bits 11 - 29, which is completely different from what I assumed and where you said it was located. I see a cluster in your screen image of the block diagram with the five fields listed (P, SSM, DATA, SDI, LABEL). I didn't realize the ARINC word has already been split up and the values placed in the cluster. Since it is only a picture of the block diagram, I can't see how the cluster was populated.
I'm glad you got it working, because I am still very confused with the way you're converting the data. Good luck!!
11-08-2017 04:16 PM
The VI I am using already splits the data into it's different components for the ARINC 429 spec.
The data comes out as a number
The SDI comes out as it's own number
The Label ""
It's a cookie cutter VI I am using from a company called united electronics incorporated.
Functionally, for this example I am only working with bits 11-29, which I can treat as bits 1-19 😄