Jump to content


Photo
- - - - -

2s complement of a string


  • Please log in to reply
20 replies to this topic

#1 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 14 March 2012 - 04:42 PM

So I need to suffix a string with a CRC, and the manual that I'm working with is very sparse on details:

Checksum must be formed and added to each command. The checksum is the two’s complement. The checksum itself is in BYTE format and thus it may rotate over the max value upon calculation.


Yep, that's really about all I know :)

So, for the following ASCII string example:

PLPARM0001:05:0004=00000032

the manual tells me that the 2s complement is 0x2E.

So I know how to do a 2s complement of numbers, and I can think of several ways to do it to a string (or, at least, representations of that string), but does anyone out there know the "right" way to do this before I try to brute force it?

post-181-1170858537.png


#2 todd

todd

    Very Active

  • Members
  • PipPipPip
  • 218 posts
  • Location:Seattle
  • Version:LabVIEW 2011
  • Since:2002

Posted 14 March 2012 - 05:12 PM

*
POPULAR

How about this?
Example_VI.png

#3 jcarmody

jcarmody

    The 500 club

  • Premium Member
  • 787 posts
  • Location:North Carolina, United State, Earth
  • Version:LabVIEW 2012
  • Since:2007

Posted 15 March 2012 - 10:28 AM

:D That made me smile. I just had to try it.

Example_VI.png

Resistance is Mandatory

No rulers
No masters
NO CONSENT

 


#4 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 15 March 2012 - 02:42 PM

OT: Does the Code Capture Tool let you grab control/indicators from the front panel too, or did you edit that in?

#5 Darin

Darin

    Very Active

  • Members
  • PipPipPip
  • 158 posts
  • Version:LabVIEW 2009
  • Since:1992

Posted 15 March 2012 - 03:02 PM

*
POPULAR

Of course if you append the checksum to the string and run it through the same code you'll see it's purpose. To save the trouble in this case you only have to figure out what x XOR x is.

#6 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 15 March 2012 - 03:30 PM

How about this?
Example_VI.png

Nice work todd - that's exactly what I needed! Nothin' like LAVA to feel humbled :)

OT: Does the Code Capture Tool let you grab control/indicators from the front panel too, or did you edit that in?

It lets you grab FP nodes too, but with some property exceptions.

post-181-1170858537.png


#7 Yair

Yair

    Extwemely Active

  • Members
  • PipPipPipPipPipPip
  • 2,644 posts
  • Version:LabVIEW 2009
  • Since:2003

Posted 15 March 2012 - 04:48 PM

OT: Does the Code Capture Tool let you grab control/indicators from the front panel too, or did you edit that in?

Like Chris said, the CCT does allow that, as well as all kinds of options (such as the placement). There are some videos about the CCT here if you want to see the various features - http://www.screencast.com/t/ZmQ1YjIxNj

#8 Phillip Brooks

Phillip Brooks

    The 500 club

  • Members
  • PipPipPipPipPip
  • 749 posts
  • Location:Boston, MA
  • Version:LabVIEW 8.6
  • Since:1999

Posted 15 March 2012 - 05:35 PM

Example_VI.png


8.2!

Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T


#9 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 15 March 2012 - 05:57 PM

8.2!

Old skool!

post-181-1170858537.png


#10 hooovahh

hooovahh

    The 500 club

  • Members
  • PipPipPipPipPip
  • 774 posts
  • Version:LabVIEW 2011
  • Since:2004

Posted 15 March 2012 - 07:52 PM

Like Chris said...

You may want to address him as crelf only because there is more than one person in this thread, with a real life name of Chris.

"Maybe Hoovah is really Crelf's alter-ego, which he uses to irk people?" - Gary Rubin

"Seemingly minor changes....can mean the difference between a working app and a quivering heap of unresponsive code." - David Boyd


#11 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 15 March 2012 - 07:54 PM

You may want to address him as crelf only because there is more than one person in this thread, with a real life name of Chris.

I was just going to let him give me credit for it...

#12 jcarmody

jcarmody

    The 500 club

  • Premium Member
  • 787 posts
  • Location:North Carolina, United State, Earth
  • Version:LabVIEW 2012
  • Since:2007

Posted 15 March 2012 - 09:16 PM


8.2!


Use the GetSnippet RCF plugin to extract snippets in LabVIEW 8.2 and above :yes:

Resistance is Mandatory

No rulers
No masters
NO CONSENT

 


#13 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 16 March 2012 - 12:26 AM

You may want to address him as crelf only because there is more than one person in this thread, with a real life name of Chris.

There are?!?

post-181-1170858537.png


#14 ShaunR

ShaunR

    LabVIEW Archetype

  • Members
  • PipPipPipPipPipPip
  • 2,223 posts
  • Version:LabVIEW 2009
  • Since:1994

Posted 16 March 2012 - 03:24 AM

As an aside.......
2's compliment as a CRC really sucks. For example, just try entering the string
PLPARM01:0500000000:0400=32

A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort. (Herm Albright 1876-1944).

Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!

#15 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 16 March 2012 - 05:24 PM

As an aside.......
2's compliment as a CRC really sucks. For example, just try entering the string

PLPARM01:0500000000:0400=32

Well, one could argue that any CRC sucks, as there aren't completely mutually-exclusive signatures for all possible permutations of a string input. I'm not saying it's the best CRC, but it's better than nothing in most practical cases, and it's what the COTS hardware manufacturer chose, so I'm stuck with it.

post-181-1170858537.png


#16 hooovahh

hooovahh

    The 500 club

  • Members
  • PipPipPipPipPip
  • 774 posts
  • Version:LabVIEW 2011
  • Since:2004

Posted 16 March 2012 - 06:23 PM

Well, one could argue that any CRC sucks, as there aren't completely mutually-exclusive signatures for all possible permutations of a string input.

This is an important thing to remember. Any CRC/checksum method will have multiple messages generate the same result. There are an infinite number of strings that will return the same MD5Sum for example. The likelihood of having two random strings generate the same MD5Sum is 1 in 340,000,000,000,000,000,000,000,000,000,000,000,000 (rounded down). Similar things can be said for GUIDs.

There have been several attempts to break MD5 in a systematic way and I believe someone was able to but I can't seem to find the example at the moment. The example was a EXE that when ran would say "Hello Wold". Then there was a second EXE with the same MD5 and when it was ran it would say something else.

"Maybe Hoovah is really Crelf's alter-ego, which he uses to irk people?" - Gary Rubin

"Seemingly minor changes....can mean the difference between a working app and a quivering heap of unresponsive code." - David Boyd


#17 ShaunR

ShaunR

    LabVIEW Archetype

  • Members
  • PipPipPipPipPipPip
  • 2,223 posts
  • Version:LabVIEW 2009
  • Since:1994

Posted 17 March 2012 - 01:02 AM

Well, one could argue that any CRC sucks, as there aren't completely mutually-exclusive signatures for all possible permutations of a string input. I'm not saying it's the best CRC, but it's better than nothing in most practical cases, and it's what the COTS hardware manufacturer chose, so I'm stuck with it.

Well. Some are better than others. But a single byte (max 256 permutations) coupled with 2's compliment yields many more collisions than is useful.
A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort. (Herm Albright 1876-1944).

Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!

#18 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 17 March 2012 - 06:21 PM

Some are better than others.

Agreed.

But a single byte (max 256 permutations) coupled with 2's compliment yields many more collisions than is useful.

Not agreed - it's certainly very weak, but that doesn't mean that it isn't useful as a really gross check. The data that I'm sending/receiving has type checks on either side, so coupled with that, this CRC method is okay as a gross indicator step of a multi-step check. I certainly wouldn't suggest it for important or deterministic streams, especially if it's the only check used.

Anyway, if I'd designed the system I wouldn't have chosen it, but I'm not going to call up the hardware vendor and tell them I refuse to use their hardware just because their CRC isn't up to snuff. :)

post-181-1170858537.png


#19 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,742 posts
  • Version:LabVIEW 2012
  • Since:1993

Posted 18 March 2012 - 05:35 PM

A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort. (Herm Albright 1876-1944).

btw: love it!

post-181-1170858537.png


#20 patleb

patleb

    Active

  • Members
  • Pip
  • 10 posts
  • Version:LabVIEW 2010
  • Since:2005

Posted 29 March 2012 - 06:49 PM

good Todd
pat