*&---------------------------------------------------------------------* *& Include ZUTIL_CONVERT_NUMBER * *& * *&---------------------------------------------------------------------* *& * *& This file is part of ZUTIL. * *& * *& ZUTIL is free software: you can redistribute it and/or modify * *& it under the terms of the GNU General Public License as published * *& by the Free Software Foundation, either version 3 of the License, * *& or any later version. * *& * *& ZUTIL is distributed in the hope that it will be useful, * *& but WITHOUT ANY WARRANTY; without even the implied warranty of * *& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * *& GNU General Public License for more details. * *& * *& You should have received a copy of the GNU General Public License * *& along with ZUTIL. If not, see . * *& * *&---------------------------------------------------------------------* *& * *& Author: Ruediger von Creytz ruediger.creytz@globalbit.net * *& Copyright: globalBIT, LLC http://www.globalbit.net * *& * *&---------------------------------------------------------------------* *----------------------------------------------------------------------- * number_to_x_char *----------------------------------------------------------------------- FORM number_to_x_char USING i_num TYPE i CHANGING c_char TYPE c. DATA: l_num TYPE i. CONSTANTS: lc_chars(26) TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. CLEAR c_char. IF i_num < 10. c_char = i_num. ELSEIF i_num < 36. l_num = i_num - 10. c_char = lc_chars+l_num(1). ENDIF. ENDFORM. "number_to_x_char *----------------------------------------------------------------------- * number_to_hex_string *----------------------------------------------------------------------- FORM number_to_hex_string USING i_num TYPE any CHANGING c_hex TYPE string. PERFORM number_to_x_string USING i_num 16 CHANGING c_hex. ENDFORM. "number_to_hex_string *----------------------------------------------------------------------- * number_to_x_string *----------------------------------------------------------------------- FORM number_to_x_string USING i_num TYPE any i_number_system TYPE i CHANGING c_hex TYPE string. DATA: l_num TYPE i, l_cal TYPE i VALUE 1, l_cnt TYPE i, l_hex_char TYPE c. CLEAR c_hex. l_num = i_num. IF l_num = 0. c_hex = '0'. ELSE. DO. l_cnt = 0. IF l_cal <= l_num. l_cal = l_cal * i_number_system. ENDIF. IF l_cal > l_num. l_cal = l_cal / i_number_system. DO. IF l_cal <= l_num. l_num = l_num - l_cal. l_cnt = l_cnt + 1. ELSE. EXIT. ENDIF. ENDDO. PERFORM number_to_x_char USING l_cnt CHANGING l_hex_char. CONCATENATE c_hex l_hex_char INTO c_hex. ENDIF. IF l_num = 0 AND l_cal = 1. EXIT. ENDIF. ENDDO. ENDIF. ENDFORM. "number_to_hex_string