hexstr2str

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
mainly written for the use in CPLwriteDXF in combination with str2codelines

See Also: str2codelines , str2hexsstr , CPLwriteDXF , hexstr2uint8

Example Illustration

 missing image of hexstr2str(hs,len)

Syntax

text=hexstr2str([hs,len])

Input Parameter

hs: rows
len: hex numbers per row ; default is 40 (80 chars)

Output Parameter

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

Examples


hs=str2hexsstr('The quick brown fox jumps over the lazy dog')
str2codelines(hs)
char(hexstr2str(hs')) % make shure that hs is a row vector




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, hexstr2str, is designed to convert a uint8 string into a hex string array. It is particularly useful for integrating default content for special format files, such as DXF, into an m-function. The function is part of the SolidGeometry library and was introduced in version 5.0.

Input Parameters

Output Results

Algorithm Steps

  1. The function begins by defining a test string, which is a series of hex values representing the phrase "Dies ist ein Test".
  2. The function retrieves the input parameter hs using getfuncparams, with the test string as a default value.
  3. The input hs is transposed to ensure it is a row vector.
  4. An empty uint8 array, text, is initialized to store the converted characters.
  5. A loop iterates over the hs array in steps of two characters (since each hex value is two characters long).
  6. For each pair of characters, the function checks if they are not spaces (' ').
  7. If the characters are not spaces, they are converted from hex to decimal using hex2dec and stored in the text array.
  8. The loop continues until all characters in hs are processed.
  9. The function returns the text array, which contains the converted string.

Example Usage

The function can be used in combination with str2hexsstr and str2codelines to convert a string into a hex string and then back into a character array:

hs = str2hexsstr('The quick brown fox jumps over the lazy dog');
str2codelines(hs);
char(hexstr2str(hs'));
Algorithm explaination created using ChatGPT on 2025-08-19 07:26. (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