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 17:32
Read: times


 
#52013 - bintohex algorithm ?
im trying to convert an 8bit binary byte to ascii hex, i cant understand why when i debug the following code with 0 (zero) as the incoming value on the tens conversion "ten_hex /= 10;" the value goes to 4
i even complied the code (with a cpl of changes) in microsoft visual c but the same thing happened

basically im getting an output of 0.44 volts when it should be 0.00. can anyone help me please as im at a loss as why?

the function is here:
void bintohex(byte bth)
{
byte data hun_hex;
byte data ten_hex;
byte data unit;

hun_hex = bth;
hun_hex /= 100;
hun_hex += 0x30;
serial[0] = hun_hex;

ten_hex = hun_hex;
ten_hex /= 10; // <--at this point we get 4
unit = ten_hex; //when bth was zero
ten_hex += 0x30;
serial[2] = ten_hex;

unit += 0x30;
serial[3] = unit;
}

this is in Keil uVision
ive noticed the compiler stores the 3 variables at the same address D:0x07 even when ive set the start address as D:0x30 why is that? this confuses the hell out of me coz how can 3 different variables share the same address?

thanks in advance
luigi



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