[U8,CSHex]=hexstr2uint8(STR)
STR : | string or char array with ot without spaces |
U8 : | Uint8 array of the hex data | |
CSHex : | Checksum in Hexadecimal |
hexstr2uint8("FFFF0105032A0010")
hexstr2uint8("FF FF 01 05 03 2A 00 10")
[a,b]=hexstr2uint8('FF FF 01 05 03 2A 00 10'), c=reshape(dec2hex(a)',[],1)'
This function, hexstr2uint8
, is designed to convert a hexadecimal string into a uint8 array. It is used for communication with the FeeTech URT-1 Board using the SCS-Protocol.
STR
to a character array using char(STR)
.STR
using strtrim(STR)
.STR
contains spaces and is either a character array or a string. If true, split STR
into separate elements using split(STR)
.STR
is greater than 2, reshape STR
into a 2-column format using reshape(STR',2,numel(STR)/2)'
.STR
and store it in nn
.STR
from hexadecimal to decimal using hex2dec(STR)
and cast it to uint8
, storing the result in U8
.U8
, taking the modulus with 255, subtracting from 255, and converting the result to hexadecimal using dec2hex
. Store this in CSHex
.Examples of how to use the function:
hexstr2uint8("FFFF0105032A0010")
hexstr2uint8("FF FF 01 05 03 2A 00 10")
[a,b]=hexstr2uint8('FF FF 01 05 03 2A 00 10'), c=reshape(dec2hex(a)',[],1)'