26 #if defined (HAVE_CONFIG_H)
49 unsigned char val = 0;
52 error (
"hex2num: invalid character '%c' found in string S", ch);
55 val =
static_cast<unsigned char> (ch -
'a' + 10);
57 val =
static_cast<unsigned char> (ch -
'A' + 10);
59 val =
static_cast<unsigned char> (ch -
'0');
67 unsigned char *cp =
reinterpret_cast<unsigned char *
> (num);
69 const size_t nc = hex.length ();
70 const size_t nchars = 2 * nbytes;
73 error (
"hex2num: S must be no more than %zd characters", nchars);
77 for (
size_t i = 0; i < nbytes; i++)
81 unsigned char ch1 = (j < nc) ? hex[j++] :
'0';
82 unsigned char ch2 = (j < nc) ? hex[j++] :
'0';
96 size_t nbytes =
sizeof (T);
161 int nargin = args.length ();
163 if (nargin < 1 || nargin > 2)
166 std::string
type =
"double";
168 type = args(1).xstring_value (
"hex2num: CLASS must be a string");
173 bool is_float =
type ==
"single" ||
type ==
"double";
178 else if (
type ==
"uint8")
180 else if (
type ==
"int16")
182 else if (
type ==
"uint16")
184 else if (
type ==
"int32")
186 else if (
type ==
"uint32")
188 else if (
type ==
"int64")
190 else if (
type ==
"uint64")
192 else if (
type ==
"char")
194 else if (
type ==
"single")
196 else if (
type ==
"double")
199 error (
"hex2num: unrecognized CLASS '%s'",
type.c_str ());
214 static inline unsigned char
228 const unsigned char *cp =
reinterpret_cast<const unsigned char *
> (p);
232 for (
size_t i = 0; i <
n; i++)
236 unsigned char ch = cp[j];
243 template <
typename T>
247 const size_t nbytes =
sizeof (T);
248 const size_t nchars = 2 * nbytes;
262 sv[i] = std::string (hex, nchars);
304 int nargin = args.length ();
306 if (nargin < 1 || nargin > 2)
309 bool as_cell =
false;
313 std::string opt = args(1).xstring_value (
"num2hex: second argument must be a string");
317 error (
"num2hex: unrecognized option '%s'", opt.c_str ());
323 error (
"num2hex: N must be real");
static void swap_bytes(void *ptr, unsigned int i, unsigned int j)
N Dimensional Array with copy-on-write semantics.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
const T * fortran_vec(void) const
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
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
bool is_single_type(void) const
uint32NDArray uint32_array_value(void) const
Array< float > float_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
bool is_uint8_type(void) const
int16NDArray int16_array_value(void) const
bool iscomplex(void) const
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 bool is_little_endian(bool is_float)
static unsigned char nibble2hex(unsigned char ch)
static void hex2num(const std::string &hex, void *num, size_t nbytes, bool swap_bytes)
static void num2hex(const void *p, size_t n, char *hex, bool swap_bytes)
static uint8_t hex2nibble(unsigned char ch)
float_format native_float_format(void)
bool words_little_endian(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()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval