26 #if defined (HAVE_CONFIG_H)
51 unsigned char val = 0;
54 error (
"hex2num: invalid character '%c' found in string S", ch);
57 val =
static_cast<unsigned char> (ch -
'a' + 10);
59 val =
static_cast<unsigned char> (ch -
'A' + 10);
61 val =
static_cast<unsigned char> (ch -
'0');
69 unsigned char *cp =
reinterpret_cast<unsigned char *
> (num);
71 const std::size_t nc = hex.length ();
72 const std::size_t nchars = 2 * nbytes;
75 error (
"hex2num: S must be no more than %zd characters", nchars);
79 for (std::size_t i = 0; i < nbytes; i++)
81 std::size_t k = (
swap_bytes ? nbytes - i - 1 : i);
83 unsigned char ch1 = (j < nc) ? hex[j++] :
'0';
84 unsigned char ch2 = (j < nc) ? hex[j++] :
'0';
98 std::size_t nbytes =
sizeof (T);
163 int nargin = args.
length ();
165 if (nargin < 1 || nargin > 2)
168 std::string type =
"double";
170 type = args(1).xstring_value (
"hex2num: CLASS must be a string");
175 bool is_float = type ==
"single" || type ==
"double";
180 else if (type ==
"uint8")
182 else if (type ==
"int16")
184 else if (type ==
"uint16")
186 else if (type ==
"int32")
188 else if (type ==
"uint32")
190 else if (type ==
"int64")
192 else if (type ==
"uint64")
194 else if (type ==
"char")
196 else if (type ==
"single")
198 else if (type ==
"double")
201 error (
"hex2num: unrecognized CLASS '%s'", type.c_str ());
216 static inline unsigned char
230 const unsigned char *cp =
reinterpret_cast<const unsigned char *
> (p);
234 for (std::size_t i = 0; i <
n; i++)
238 unsigned char ch = cp[j];
245 template <
typename T>
249 const std::size_t nbytes =
sizeof (T);
250 const std::size_t nchars = 2 * nbytes;
256 const T *pv = v.
data ();
264 sv[i] = std::string (hex, nchars);
306 int nargin = args.length ();
308 if (nargin < 1 || nargin > 2)
311 bool as_cell =
false;
315 std::string opt = args(1).xstring_value (
"num2hex: second argument must be a string");
319 error (
"num2hex: unrecognized option '%s'", opt.c_str ());
325 error (
"num2hex: N must be real");
static void swap_bytes(void *ptr, unsigned int i, unsigned int j)
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
string_vector string_vector_value(void) const
int32NDArray int32_array_value(void) const
uint16NDArray uint16_array_value(void) const
bool is_uint16_type(void) const
bool is_char_matrix(void) const
bool is_int8_type(void) const
charNDArray char_array_value(bool frc_str_conv=false) const
bool is_double_type(void) const
bool is_uint32_type(void) const
int8NDArray int8_array_value(void) const
bool is_int64_type(void) const
int64NDArray int64_array_value(void) const
uint8NDArray uint8_array_value(void) const
bool is_int32_type(void) const
bool is_uint64_type(void) const
bool is_int16_type(void) const
uint64NDArray uint64_array_value(void) const
bool is_single_type(void) const
uint32NDArray uint32_array_value(void) const
OCTINTERP_API Array< float > float_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
OCTINTERP_API octave_idx_type length(void) const
bool is_uint8_type(void) const
int16NDArray int16_array_value(void) const
OCTINTERP_API Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
bool iscomplex(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
void err_wrong_type_arg(const char *name, const char *s)
static void num2hex(const void *p, std::size_t n, char *hex, bool swap_bytes)
static bool is_little_endian(bool is_float)
static void hex2num(const std::string &hex, void *num, std::size_t nbytes, bool swap_bytes)
static unsigned char nibble2hex(unsigned char ch)
static uint8_t hex2nibble(unsigned char ch)
bool words_little_endian(void)
float_format native_float_format(void)
@ flt_fmt_ieee_little_endian
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))