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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/06/09 23:18
Read: times


 
#162157 - Keep track of binary/BCD/hex/ASCII
Responding to: ???'s previous message
Erik did write 030h which is hexadecimal and written 0x30 in C. The corresponding decimal value is 48, but it is better to write '0' and let the compiler worry about the numeric value for the '0' character.

If you have a number 1388 stored in BCD format, i.e. four bits/digit, then you convert as:

long value = 0x1388;
digit1 = ((value >> 12) & 0x0f) + '0';
digit2 = ((value >> 8) & 0x0f) + '0';
digit3 = ((value >> 4) & 0x0f) + '0';
digit4 = (value & 0x0f) + '0';

If you the value was stored in binary form, then you convert as:

long value = 1388;
digit1 = (value / 1000) + '0';
digit2 = ((value / 100) % 10) + '0';
digit3 = ((value / 10) % 10) + '0';
digit4 = (value % 10) + '0';



List of 12 messages in thread
TopicAuthorDate
Looking for a fast elegant solution to an SAA1064            01/01/70 00:00      
   several ways            01/01/70 00:00      
   Simple Table Lookup            01/01/70 00:00      
      Constructing the table symbolically            01/01/70 00:00      
      That looks like it will do the trick            01/01/70 00:00      
      Ok I'm here now.......            01/01/70 00:00      
         first convert to decimal, then to ASCII            01/01/70 00:00      
            So...            01/01/70 00:00      
               Keep track of binary/BCD/hex/ASCII            01/01/70 00:00      
                  Final answer and it works            01/01/70 00:00      
                     But '0' - 0x30 is zero :)            01/01/70 00:00      
               not exactly            01/01/70 00:00      

Back to Subject List