comparison src/DLD-FUNCTIONS/hex2num.cc @ 10154:40dfc0c99116

DLD-FUNCTIONS/*.cc: untabify
author John W. Eaton <jwe@octave.org>
date Wed, 20 Jan 2010 17:33:41 -0500
parents 34d6f005db4b
children 89f4d7e294cc
comparison
equal deleted inserted replaced
10153:2c28f9d0360f 10154:40dfc0c99116
59 else 59 else
60 { 60 {
61 const charMatrix cmat = args(0).char_matrix_value (); 61 const charMatrix cmat = args(0).char_matrix_value ();
62 62
63 if (cmat.columns () > 16) 63 if (cmat.columns () > 16)
64 error ("hex2num: expecting no more than a 16 character string"); 64 error ("hex2num: expecting no more than a 16 character string");
65 else if (! error_state) 65 else if (! error_state)
66 { 66 {
67 octave_idx_type nr = cmat.rows (); 67 octave_idx_type nr = cmat.rows ();
68 octave_idx_type nc = cmat.columns (); 68 octave_idx_type nc = cmat.columns ();
69 ColumnVector m (nr); 69 ColumnVector m (nr);
70 70
71 for (octave_idx_type i = 0; i < nr; i++) 71 for (octave_idx_type i = 0; i < nr; i++)
72 { 72 {
73 union 73 union
74 { 74 {
75 uint64_t ival; 75 uint64_t ival;
76 double dval; 76 double dval;
77 } num; 77 } num;
78 78
79 for (octave_idx_type j = 0; j < nc; j++) 79 for (octave_idx_type j = 0; j < nc; j++)
80 { 80 {
81 unsigned char ch = cmat.elem (i, j); 81 unsigned char ch = cmat.elem (i, j);
82 82
83 if (isxdigit (ch)) 83 if (isxdigit (ch))
84 { 84 {
85 num.ival <<= 4; 85 num.ival <<= 4;
86 if (ch >= 'a') 86 if (ch >= 'a')
87 num.ival += static_cast<uint64_t> (ch - 'a' + 10); 87 num.ival += static_cast<uint64_t> (ch - 'a' + 10);
88 else if (ch >= 'A') 88 else if (ch >= 'A')
89 num.ival += static_cast<uint64_t> (ch - 'A' + 10); 89 num.ival += static_cast<uint64_t> (ch - 'A' + 10);
90 else 90 else
91 num.ival += static_cast<uint64_t> (ch - '0'); 91 num.ival += static_cast<uint64_t> (ch - '0');
92 } 92 }
93 else 93 else
94 { 94 {
95 error ("hex2num: illegal character found in string"); 95 error ("hex2num: illegal character found in string");
96 break; 96 break;
97 } 97 }
98 } 98 }
99 99
100 if (error_state) 100 if (error_state)
101 break; 101 break;
102 else 102 else
103 { 103 {
104 if (nc < 16) 104 if (nc < 16)
105 num.ival <<= (16 - nc) * 4; 105 num.ival <<= (16 - nc) * 4;
106 106
107 m(i) = num.dval; 107 m(i) = num.dval;
108 } 108 }
109 } 109 }
110 110
111 if (! error_state) 111 if (! error_state)
112 retval = m; 112 retval = m;
113 } 113 }
114 } 114 }
115 115
116 return retval; 116 return retval;
117 } 117 }
118 118
148 else 148 else
149 { 149 {
150 const ColumnVector v (args(0).vector_value ()); 150 const ColumnVector v (args(0).vector_value ());
151 151
152 if (! error_state) 152 if (! error_state)
153 { 153 {
154 octave_idx_type nr = v.length (); 154 octave_idx_type nr = v.length ();
155 charMatrix m (nr, 16); 155 charMatrix m (nr, 16);
156 const double *pv = v.fortran_vec (); 156 const double *pv = v.fortran_vec ();
157 157
158 for (octave_idx_type i = 0; i < nr; i++) 158 for (octave_idx_type i = 0; i < nr; i++)
159 { 159 {
160 union 160 union
161 { 161 {
162 uint64_t ival; 162 uint64_t ival;
163 double dval; 163 double dval;
164 } num; 164 } num;
165 165
166 num.dval = *pv++; 166 num.dval = *pv++;
167 167
168 for (octave_idx_type j = 0; j < 16; j++) 168 for (octave_idx_type j = 0; j < 16; j++)
169 { 169 {
170 unsigned char ch = 170 unsigned char ch =
171 static_cast<char> (num.ival >> ((15 - j) * 4) & 0xF); 171 static_cast<char> (num.ival >> ((15 - j) * 4) & 0xF);
172 if (ch >= 10) 172 if (ch >= 10)
173 ch += 'a' - 10; 173 ch += 'a' - 10;
174 else 174 else
175 ch += '0'; 175 ch += '0';
176 176
177 m.elem (i, j) = ch; 177 m.elem (i, j) = ch;
178 } 178 }
179 } 179 }
180 180
181 retval = m; 181 retval = m;
182 } 182 }
183 } 183 }
184 184
185 return retval; 185 return retval;
186 } 186 }
187 187