Menu

combining two numbers

Help
2009-02-23
2013-05-30
  • Nobody/Anonymous

    i need to make a new number from 2 numbers, ex. A and B become "AB" not A+B how do i do this?

     
    • Nobody/Anonymous

      You need to create a word variable in order to have a 16 bit value, then you can do this way

      __________________________________

      dim variableA as byte
      dim variableB as byte
      dim combinedAB as word

      combinedAB = B

      combinedAB_H = A
      __________________________________

      Note that variableA is in high byte, just like this: variableAvariableB

       
      • Nobody/Anonymous

        will this work for alpha numeric combinations? like hex numbers ex. "3F"

         
    • Nobody/Anonymous

      Do you want to "combine" two bytes or two nibbles... can you give a concrete example???

       
    • Nobody/Anonymous

      i am having the pic convert decimal numbers into 2 digit hex and send them out serially.
      ex. 27 into "1" "B" and I want to send "1B" out my serial pin

       
    • kent_twt4

      kent_twt4 - 2009-02-28

      There is a sub LCDHex(In LCDValue) in the lcd.h file.  Sounds like what you need.

       
    • Santiago

      Santiago - 2009-02-28

      Hi...
      If you want something to manage ascii data, the function sugested by Kent could be what you need.

      Anyway i don't understand what you mean... as 27 is the same than 1B, if you send 27 you are sending 0x1B or 00011011 there are just different ways of representing the same value.

      if you want send 0x01 and then 0x0B you can do:

      variable = 27

      first_value = variable and 0x0F
      second_value = variable and 0xF0

      'Now you have:

      first_value = 0x0B = 11 = b'00001011'
      second_value = 0x01 = 1 = b'00000001'

       
    • Nobody/Anonymous

      i am having the pic convert decimal numbers into 2 digit hex and send them out serially.
      ex. 27 into "1" "B" and I want to send "1B" out my serial pin

       
    • Nobody/Anonymous

      i need to send it out as hex from the pic, they are control commands for a camera that is looking for hex to be sent to it, like "1F" "0A" etc., so what you are saying is if i tell it to send "27" or "1B" the output is the same thing?

       
    • Nobody/Anonymous

      Yes "27" and "1B" is the same thing

      you can send hex values this format: 0x1B
      or you can send: 27

      The received data will be the same in both cases.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.