Table 2: SerialReadHexDigit function (char) (int) SerialReadHexDigit(digit) digit 0 ‘0’ 1 ‘1’ 2 ‘2’ 3 ‘3’ 4 ‘4’ 5 ‘5’ 6 ‘6’ 7 ‘7’ 8 ‘8’ 9 ‘9’ or 10 ‘a’ ‘A’ or 11 ‘b’ ‘B’ or 12 ‘c’ ‘C’ or 13 ‘d’ ‘D’ or 14 ‘e’ ‘E’ or 15 ‘f’ ‘F’ Firmware Part 4 ItoB(unsigned long integer, int length) – 1 void ItoB(unsigned long integer, int length){ //needs bit2[length] 2 Serial.println("ItoB"); // for debugging 3 purposes 4 for (int i=0; i<length; i++){ if ((integer / power2(length-1-i))==1){ 5 integer-=power2(length-1-i); 6 bit2[i]=1; 7 } 8 else bit2[i]=0; 9 Serial.print(bit2[i]); 10 } 11 Serial.println(); 12 } 13 The (stands for to Binary’) method takes the integer form of the ItoB() ‘Integer command string, and stores the binary bits into the array bit2. Notice that the array bit2 was declared with length 22 (see the variable declaration line 28).
Table 2: SerialReadHexDigit function (char) digit (int) SerialReadHexDigit(digit) ‘0’ 0 ‘1’ 1 ‘2’ 2 ‘3’ 3 ‘4’ 4 ‘5’ 5 ‘6’ 6 ‘7’ 7 ‘8’ 8 ‘9’ 9 ‘a’ or ‘A’ 10 ‘b’ or ‘B’ 11 ‘c’ or ‘C’ 12 ‘d’ or ‘D’ 13 ‘e’ or ‘E’ 14 ‘f’ or ‘F’ 15 Firmware Part 4 – ItoB(unsigned long integer, int length) 1 void ItoB(unsigned long integer, int length){ //needs bit2[length] Serial.println("ItoB"); // for debugging purposes for (int i=0; i<length; i++){ if ((integer / power2(length-1-i))==1){ integer-=power2(length-1-i); bit2[i]=1; } else bit2[i]=0; Serial.print(bit2[i]); } Serial.println(); } 2 3 4 5 6 7 8 9 10 11 12 13 The ItoB() (stands for ‘Integer to Binary’) method takes the integer form of the command string, and stores the binary bits into the array bit2. Notice that the array bit2 was declared with length 22 (see the variable declaration line 28).