str2hexsstr

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Text/Strs/Chars/Links
Introduced first in SolidGeometry 5.0, Creation date: 2021-01-26, Last change: 2025-09-15

converts a uint8 string into a hex string array

Description

This function is helpful in combination with str2codelines to integrate default content for special format files to write such as DXF into an m function

See Also: str2codelines , hexstr2str , hexstr2uint8

Example Illustration

 missing image of str2hexsstr(text,len)

Syntax

TT=str2hexsstr([text,len])

Input Parameter

text: char array or uint8 array to convert into hex
len: hex numbers per row ; default is 40 (80 chars)

Output Parameter

TT: String array with [... x len] chars

Examples


hs=str2hexsstr('The quick brown fox jumps over the lazy dog')
str2codelines(hs)




Copyright 2021-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, str2hexsstr, converts a given string or uint8 array into a hexadecimal string array. It is part of the SolidGeometry library and is useful for integrating default content for special format files, such as DXF, into an m-function.

Input Parameters

Output

Algorithm Steps

  1. Retrieve the input parameters using the getfuncparams function. If not provided, default values are used: 'TEST' for text and 40 for len.
  2. Calculate the number of elements in text using numel.
  3. Determine the number of lines required to represent the text in hexadecimal format by dividing the number of elements by len and rounding up using ceil.
  4. Initialize the output array TT with spaces, having dimensions of lin by len.
  5. Iterate over each line (from 1 to lin).
  6. For each line, iterate over each position (from 1 to len).
  7. Calculate the current character position c in the text.
  8. If c is within the bounds of the text length, convert the character at position c to its hexadecimal representation using dec2hex and uint8.
  9. Ensure the hexadecimal string is two characters long by prepending '00' and taking the last two characters.
  10. Assign the two-character hexadecimal string to the appropriate position in the TT array.

This function is particularly useful for converting strings into a format that can be easily integrated into other functions or files that require hexadecimal representation.

Algorithm explaination created using ChatGPT on 2025-08-19 01:36. (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