khiops icon indicating copy to clipboard operation
khiops copied to clipboard

Add data transformation functions for hex decoding and bit extraction

Open n-voisine opened this issue 5 months ago • 1 comments

We need to implement new data transformation functions to enhance our data processing capabilities:

  1. Hexadecimal decoding: Convert a hex-encoded string into its corresponding integer value.
  2. Bit extraction: Extract specific bits from an integer and convert them into either an integer or a string representation (e.g., "001").

For example, a function like GETBIT(integer, 4, 6) should extract bits 4 to 6 from the given integer and return the result as either an integer or a string, depending on the use case.

en SQL il y a les operateur de format et de conversion hexa et de transformeiotn de bit << >> & et |

n-voisine avatar Jul 09 '25 14:07 n-voisine

Ce type de règle de dérivation n'existe pas actuellement. Mais à partir de ce besoin exprimé, on va pouvoir spécifier de nouvelle règles de conversion entre représentation hexa et numériques, analyse des bits d'un entier...

En attendant, même si c'est un peu laborieux, on peu utiliser la règle de dérivation ReplaceAll pour remplacer chaque caractère hexa en une chaine de 4 bits. Exemple: EC3A -> 1110110000111010 Ensuite, avec la règle de dérivation Categorical Middle(Categorical value, Numerical startChar, Numerical charNumber), on peut extraire la sous-partie des bits d'intérêt.

Voici un exemple d'un dictionaire .kdic de transformation d'une chaine hexa en chaine de bits:

Dictionary	Data
{
	Categorical	HexaString		;	
Unused	Categorical	_HexaString0 = ReplaceAll(HexaString, 1, "0", "G");
Unused	Categorical	_HexaString1 = ReplaceAll(_HexaString0, 1, "1", "0001");
Unused	Categorical	_HexaString2 = ReplaceAll(_HexaString1, 1, "2", "0010");
Unused	Categorical	_HexaString3 = ReplaceAll(_HexaString2, 1, "3", "0011");
Unused	Categorical	_HexaString4 = ReplaceAll(_HexaString3, 1, "4", "0100");
Unused	Categorical	_HexaString5 = ReplaceAll(_HexaString4, 1, "5", "0101");
Unused	Categorical	_HexaString6 = ReplaceAll(_HexaString5, 1, "6", "0110");
Unused	Categorical	_HexaString7 = ReplaceAll(_HexaString6, 1, "7", "0111");
Unused	Categorical	_HexaString8 = ReplaceAll(_HexaString7, 1, "8", "1000");
Unused	Categorical	_HexaString9 = ReplaceAll(_HexaString8, 1, "9", "1001");
Unused	Categorical	_HexaStringA = ReplaceAll(_HexaString9, 1, "A", "1010");
Unused	Categorical	_HexaStringB = ReplaceAll(_HexaStringA, 1, "B", "1011");
Unused	Categorical	_HexaStringC = ReplaceAll(_HexaStringB, 1, "C", "1100");
Unused	Categorical	_HexaStringD = ReplaceAll(_HexaStringC, 1, "D", "1101");
Unused	Categorical	_HexaStringE = ReplaceAll(_HexaStringD, 1, "E", "1110");
Unused	Categorical	_HexaStringF = ReplaceAll(_HexaStringE, 1, "F", "1111");
	Categorical	BinaryString = ReplaceAll(_HexaStringF, 1, "G", "0000");
};

Et un exemple de fichier Data.txt en entrée, transformé en D_Data.txt par déploiement de ce dictionnaire. Data.txt D_Data.txt

marcboulle avatar Jul 09 '25 15:07 marcboulle