hexstr2uint8

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 5.4, Creation date: 2024-04-03, Last change: 2025-09-15

converts a hexadecimal string into a uint8 array

Description

used for the communication with the FeeTech URT-1 Board SCS-Protocoll

See Also: hexstr2str , str2hexsstr

Example Illustration

 missing image of hexstr2uint8(STR)

Syntax

[U8,CSHex]=hexstr2uint8(STR)

Input Parameter

STR: string or char array with ot without spaces

Output Parameter

U8: Uint8 array of the hex data
CSHex: Checksum in Hexadecimal

Examples


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)'




Copyright 2024-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

Output Results

Algorithm Steps

  1. Convert the input STR to a character array using char(STR).
  2. Remove any leading or trailing whitespace from STR using strtrim(STR).
  3. Check if STR contains spaces and is either a character array or a string. If true, split STR into separate elements using split(STR).
  4. If the number of columns in STR is greater than 2, reshape STR into a 2-column format using reshape(STR',2,numel(STR)/2)'.
  5. Determine the number of rows in STR and store it in nn.
  6. Convert each element of STR from hexadecimal to decimal using hex2dec(STR) and cast it to uint8, storing the result in U8.
  7. Calculate the checksum by summing the elements of U8, taking the modulus with 255, subtracting from 255, and converting the result to hexadecimal using dec2hex. Store this in CSHex.

Example Usage

Examples of how to use the function:

Algorithm explaination created using ChatGPT on 2025-08-19 00:22. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21