projects/maven/mag/
checksum_16bits.pro
*NAME: CHECKSUM_16BITS *PURPOSE: Calculate a 16 bit checksum. Also converts 2 bytes into hexidecimal. *CALLING SEQUENCE: checksum_16bits,byte_buff,hex_string,/rfc1071,/debug,/complement, /lastbitzero *PARAMETERS: byte_buff (input) (array) (integer) The array of values to be used to determine the checksum. hex_string (output) (scalar) (string) The hexidecimal checksum value. rfc1071 (input) (keyword) (integer) When set, the RFC1071 formula is followed which includes wrap during addition. http://www.faqs.org/rfcs/rfc1071.html When only 2 bytes are supplied in input, this has no meaning since no addition is done. debug (input) (keyword) (integer) Set for debug output. lastbitzero (input) (keyword) (integer) Last bit is zero for the calculated checksum value. This is needed for data that is from the MAVEN MAG instruments (without processing thr the PFP). *EXAMPLES: 2 bytes examples temp = [248b, 95b] checksum_16bits,temp,hex_string & print,hex_string F85F temp = [0b, 0b] checksum_16bits,temp,hex_string & print,hex_string 0000 temp = [77b, 239b] checksum_16bits,temp,hex_string & print,hex_string 4DEF temp = [77b, 239b] checksum_16bits,temp,hex_string & print,hex_string,/lastbitzero 4DEE addition example temp = [69b, 0b, 0b, 52b, 0b, 0b, 64b, 0b, 255b, 17b, $ 192b, 168b, 1b, 7b, 192b, 168b, 1b, 1b] without rfc1071 checksum_16bits,temp,hex_string & print,hex_string 079D with rfc1071 checksum_16bits,temp,hex_string,/rfc1071 & print,hex_string 07A0 another addition example temp = [69b, 0b, 0b, 52b, 0b, 0b, 64b, 0b, 255b, 17b, $ 248b, 95b, 192b, 168b, 1b, 7b, 192b, 168b, 1b, 1b] without rfc1071 checksum_16bits,temp,hex_string & print,hex_string FFFC with rfc1071 checksum_16bits,temp,hex_string,/rfc1071 & print,hex_string FFFF *SYSTEM VARIABLES USED: none *INTERACTIVE INPUT: none *SUBROUTINES CALLED: none *FILES USED: none *SIDE EFFECTS: *RESTRICTIONS: Input must be in multiples of 2 bytes (16 bits). *NOTES: *PROCEDURE: Confirm multiple of 2 bytes. Split bytes into bits. Reverse bits. Reformat to 16 bit array. If more than 2 bytes Add bits. Calculate remainder in base 2. If RFC1071 keyword is set, wrap carry. Determine hexidecimal value and return. *MODIFICATION HISTORY: 14 Dec 2009 PJL wrote 15 Dec 2009 PJL changed 2 byte case to use same convert to hexidecimal logic; added examples 8 Dec 2010 PJL add returning the bit value of the checksum 16 Dec 2010 PJL addeed complement keyword to obtain one's complement checksum 11 Dec 2013 PJL lastbitzero keyword added
Routines
top source checksum_16bits
checksum_16bits, byte_buff, hex_string, bit_value, rfc1071=rfc1071, debug=debug, complement=complement, lastbitzero=lastbitzero
Parameters
- byte_buff
- hex_string
- bit_value
Keywords
- rfc1071
- debug
- complement
- lastbitzero
File attributes
Modification date: | Thu Apr 10 11:53:07 2014 |
Lines: | 78 |