Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/03/03 18:17
Read: times


 
#52015 - RE: bintohex algorithm ?
Responding to: ???'s previous message
You are actually trying (unsuccessfully) to convert a binary byte value to DECIMAL. The compiler is rather smart and realized that you use all three of the variables in a serial manner and can assign them all to the same location without conflict!!

Here is how to change your code to get the result
you are looking for.
void bintodec(byte bth) 
{ 
    byte data hun_dec; 
    byte data ten_dec; 
    byte data unit_dec; 

    hun_dec = bth;           // get 100s digit value
    hun_dec /= 100; 
    hun_dec += 0x30;         // convert digit to ASCII
    serial[0] = hun_dec;     // put into convert buffer

    ten_dec = bth % 100;     // get remainder from 100s calc
    unit_dec = ten_dec % 10; // get remainder from 10s calc
    ten_dec /= 10;           // get 10s digit value
    ten_dec += 0x30;         // make 10s into ASCII
    serial[2] = ten_dec;     // place 10s into convert buffer

    unit_dec += 0x30;        // convert units into ASCII
    serial[3] = unit_dec;    // put units into buffer
} 


Please note that I did not compile this so it may need some cleanup or debugging.

Michael Karas


List of 9 messages in thread
TopicAuthorDate
bintohex algorithm ?            01/01/70 00:00      
   RE: bintohex algorithm ?            01/01/70 00:00      
   RE: bintohex algorithm ?            01/01/70 00:00      
   RE: bintohex algorithm ?            01/01/70 00:00      
      RE: bintohex algorithm ?            01/01/70 00:00      
         RE: bintohex algorithm ?            01/01/70 00:00      
   I AM AMAZED            01/01/70 00:00      
      RE: I AM AMAZED            01/01/70 00:00      
         RE: I AM AMAZED            01/01/70 00:00      

Back to Subject List