24 #if defined (HAVE_CONFIG_H) 47 unsigned char val = 0;
50 error (
"hex2num: invalid character '%c' found in string S", ch);
53 val =
static_cast<unsigned char> (ch -
'a' + 10);
55 val =
static_cast<unsigned char> (ch -
'A' + 10);
57 val =
static_cast<unsigned char> (ch -
'0');
65 unsigned char *cp =
reinterpret_cast<unsigned char *
> (num);
67 const size_t nc = hex.length ();
68 const size_t nchars = 2 * nbytes;
71 error (
"hex2num: S must be no more than %d characters", nchars);
75 for (
size_t i = 0;
i < nbytes;
i++)
79 unsigned char ch1 = (j < nc) ? hex[j++] :
'0';
80 unsigned char ch2 = (j < nc) ? hex[j++] :
'0';
94 size_t nbytes =
sizeof (T);
166 type = args(1).xstring_value (
"hex2num: CLASS must be a string");
171 bool is_float =
type ==
"single" ||
type ==
"double";
176 else if (
type ==
"uint8")
178 else if (
type ==
"int16")
180 else if (
type ==
"uint16")
182 else if (
type ==
"int32")
184 else if (
type ==
"uint32")
186 else if (
type ==
"int64")
188 else if (
type ==
"uint64")
190 else if (
type ==
"char")
192 else if (
type ==
"single")
194 else if (
type ==
"double")
197 error (
"hex2num: unrecognized CLASS '%s'",
type.c_str ());
212 static inline unsigned char 213 nibble2hex (
unsigned char ch)
224 num2hex (
const void *
p,
size_t n,
char *hex,
bool swap_bytes)
226 const unsigned char *cp =
reinterpret_cast<const unsigned char *
> (
p);
230 for (
size_t i = 0;
i < n;
i++)
234 unsigned char ch = cp[j];
236 hex[
k++] = nibble2hex ((ch >> 4) & 0xF);
237 hex[
k++] = nibble2hex (ch & 0xF);
241 template <
typename T>
245 const size_t nbytes =
sizeof (T);
246 const size_t nchars = 2 * nbytes;
266 DEFUN (num2hex, args, ,
302 int nargin = args.length ();
307 bool as_cell =
false;
311 std::string opt = args(1).xstring_value (
"num2hex: second argument must be a string");
315 error (
"num2hex: unrecognized option '%s'", opt.c_str ());
320 if (
val.iscomplex ())
321 error (
"num2hex: N must be real");
326 bool is_float =
val.is_single_type () ||
val.is_double_type ();
329 if (
val.is_int8_type ())
331 else if (
val.is_int16_type ())
333 else if (
val.is_int32_type ())
335 else if (
val.is_int64_type ())
337 else if (
val.is_uint8_type ())
339 else if (
val.is_uint16_type ())
341 else if (
val.is_uint32_type ())
343 else if (
val.is_uint64_type ())
345 else if (
val.is_char_matrix ())
347 else if (
val.is_single_type ())
349 else if (
val.is_double_type ())
static void swap_bytes(void *ptr, unsigned int i, unsigned int j)
static void hex2num(const std::string &hex, void *num, size_t nbytes, bool swap_bytes)
OCTINTERP_API void print_usage(void)
identity matrix If supplied two scalar respectively For allows like xample val
const T * fortran_vec(void) const
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
static uint8_t hex2nibble(unsigned char ch)
float_format native_float_format(void)
void err_wrong_type_arg(const char *name, const char *s)
With real return the complex result
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
N Dimensional Array with copy-on-write semantics.
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
bool words_little_endian(void)
static bool is_little_endian(bool is_float)