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
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
- text: A character array or uint8 array that needs to be converted into a hexadecimal string.
- len: The number of hexadecimal numbers per row. The default value is 40, which corresponds to 80 characters.
Output
- TT: A string array with dimensions [... x len] characters, representing the hexadecimal conversion of the input text.
Algorithm Steps
- Retrieve the input parameters using the
getfuncparams function. If not provided, default values are used: 'TEST' for text and 40 for len.
- Calculate the number of elements in
text using numel.
- 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.
- Initialize the output array
TT with spaces, having dimensions of lin by len.
- Iterate over each line (from 1 to
lin).
- For each line, iterate over each position (from 1 to
len).
- Calculate the current character position
c in the text.
- If
c is within the bounds of the text length, convert the character at position c to its hexadecimal representation using dec2hex and uint8.
- Ensure the hexadecimal string is two characters long by prepending '00' and taking the last two characters.
- 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