26 #if defined (HAVE_CONFIG_H)
41 is_little_endian (
bool is_float)
49 hex2nibble (
unsigned char ch)
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');
67 hex2num (
const std::string& hex,
void *num, std::size_t nbytes,
bool swap_bytes)
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';
86 cp[k] = (hex2nibble (ch1) << 4) + hex2nibble (ch2);
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";
176 bool swap_bytes = is_little_endian (is_float);
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
217 nibble2hex (
unsigned char ch)
228 num2hex (
const void *p, std::size_t
n,
char *hex,
bool swap_bytes)
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];
240 hex[k++] = nibble2hex ((ch >> 4) & 0xF);
241 hex[k++] = nibble2hex (ch & 0xF);
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");
331 bool swap_bytes = is_little_endian (is_float);
384 OCTAVE_END_NAMESPACE(
octave)
void swap_bytes(void *ptr)
const T * data() const
Size of the specified dimension.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
string_vector string_vector_value() const
bool is_uint32_type() const
int32NDArray int32_array_value() const
uint16NDArray uint16_array_value() const
int16NDArray int16_array_value() const
int8NDArray int8_array_value() const
bool is_int8_type() const
bool is_single_type() const
charNDArray char_array_value(bool frc_str_conv=false) const
bool is_uint8_type() const
bool is_uint64_type() const
bool is_uint16_type() const
uint64NDArray uint64_array_value() const
bool is_int16_type() const
bool is_char_matrix() const
bool is_int64_type() const
int64NDArray int64_array_value() const
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
octave_idx_type length() const
bool is_double_type() const
bool is_int32_type() const
uint8NDArray uint8_array_value() const
Array< float > float_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
uint32NDArray uint32_array_value() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#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)
Array< T > hex2num(const Array< std::string > &val, bool swap_bytes)
Cell num2hex(const Array< T > &v, bool swap_bytes)
bool words_little_endian()
float_format native_float_format()
@ 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()) ? '\'' :'"'))