LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1's compliment?

As part of a BCC calculation, I need to "Take the last 2 characters of the 1's compliment".  But I'm having so much trouble with this one that I'm not even sure how to word the question correctly.

Essentially I have ASCII code for 12 characters.  I need to sum the HEX values of these 12 characters.  I then need to convert this HEX value into a Binary number and "flip" all the bits.  Then add one, and keep the two least significant digits.  

I've spent the last four hours trying different things here, and I'm getting nowhere.  Any suggestions are greatly appreciated.
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 1 of 10
(4,483 Views)
Your story is a bit confusing to me.
 
BCC calculation   or do you mean BCD calculation
 
Take the last 2 characters   or do you mean the last 2 bits
 
1's compliment... Then add one doesn't make sense to me
 
 
and I think you mixed up 1's and 2's complement.
 
5 is  0101 in binary and is 1010 in 1's complement (just invert it)
 
5 is  0101 in binary and  -5  is 1011 in 2's complement
 
Can you tell a bit more of what you want to do
0 Kudos
Message 2 of 10
(4,468 Views)
"I then need to convert this HEX value into a Binary number and "flip" all the bits.  Then add one, and keep the two least significant digits. "
 
The attached Labview 8 vi does the above, if I understand your request.  I start with a U8 control, then:
Number to Boolean Array
Negate
Boolean Array to Number
Increment
To Unsigned Byte Integer
 
voila
 
Message 3 of 10
(4,464 Views)
Thanks Paul.  But unfortunately I'm still using LV 7.1  Smiley Sad
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 4 of 10
(4,460 Views)
Here is want you want I think. You can invert a number and AND it with 3 for the least 2 bits
0 Kudos
Message 5 of 10
(4,458 Views)
It's confusing for me too KC.   🙂

BCC apparently stands for Binary Cross Check.

To send a serial command to this particular controller (IAI RCP2) I need to add the ASCII codes for 12 data characters.  This will give me a HEX number.  (IE 2FA)

I then need to convert that number to binary and "flip" all the bits.  (IE any zero becomes a one and vice versa)  

Then, add one.  

Then convert back to HEX and keep the two least significant digits.  

Although this seems like a pretty convoluted way to get a check bit, it does work for me when I do it manually on a calculator.  

I'm very new to this type of communication, so I'm not sure if this is what would be called a "twos complement" or not.  So far nothing I've tried has worked correctly for me.  

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 6 of 10
(4,447 Views)
Um....no.  I don't think that's it either. 

Thanks though. 
---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 7 of 10
(4,439 Views)
Is this something ? Can you show me what your calculation result looks like.
 
In what format do you send the check bits ?

Message Edited by K C on 12-21-2005 09:36 PM

0 Kudos
Message 8 of 10
(4,436 Views)

The last 2 bits indicator is binary. I don't know if you have to send this as binary or convert this to ascii or ....  It is all possible but i don't know what you need

 

0 Kudos
Message 9 of 10
(4,417 Views)
I think I probably wasn't describing things correctly.  Looks like what I needed was a "bitwise" 2's compliment.

Ben Rayner posted a solution here:

http://forums.ni.com/ni/board/message?board.id=170&message.id=70416&a#M70416

With a slight modification, this is exactly what I need.  🙂


---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 10 of 10
(4,408 Views)