01-05-2006 08:46 AM
01-05-2006 09:01 AM
for (num = 0, i = 0; i < 16; i++) {
if (t[i]) num += t[i] * pow(2, i + 1);
}
<num> will hold the decimal number corresponding to the given binary pattern (t[15] = msb ÷ t[0] = lsb)
01-05-2006 09:07 AM
01-05-2006 09:10 AM
01-05-2006 09:15 AM
Si, certo, mi sono incastrato con gli indici... ![]()
Grazie
Roberto
01-05-2006 10:45 AM - edited 01-05-2006 10:45 AM
Isn't it fascinating to compare different programmers' styles? I would do it thus:
for (num = i = 0; i < 16; i++)
num += t [i] << i;
JR
Message Edited by jr_2005 on 01-05-2006 04:46 PM
01-05-2006 10:53 AM
01-05-2006 11:04 AM
I first started programming in the days when 1K of memory was considered a lot and CPU speeds were measured with a sun-dial. Got into the habit of 'optimising' my code for conciseness and efficiency - old habits die hard! ![]()
JR
01-05-2006 05:26 PM
I've started a bit later than you: in my first BASIC applications I could rely on a *HUGE* memory of 512 kB for the OS and applications! ![]()
But due to the fact that even in these years BASIC was not a low-level language, I am not so fond on byte shifting, bit comparisons and so on...
01-06-2006 03:42 AM