1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Ranges

Discussion in 'Assembly Language Programming (ALP) Forum' started by Shafqat, Dec 11, 2008.

  1. Shafqat

    Shafqat New Member

    Joined:
    Nov 27, 2008
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    If it is given that the range of a certain string is from 0x0000 to 0xFFFF, does this imply that each character in the string is 16 bits long?

    I'm trying to write a subroutine that converts ASCII dec string into binary and vice versa.

    The hints I'm given say that for conversion from ASCII dec to binary I must:

    subtract 0x30 from every digit - I think this is so you can get the digit in base 10 as we know it.

    Then I am to multiply each digit by its weight and then sum up all of this to get the binary value.

    This last step makes no sense to me as the way I have learnt it converting from dec to binary requires divisions by 2 and then recording the remainders etc. Is there another way I am unaware of?

    Similarly to convert from binary to decimal I'm asked to use a division method but the only way I am aware of coverting from bin to dec is to multiply by weights.

    Any advice?

    Thanks
     
    Last edited: Dec 11, 2008
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Probably yes, but I'd want something else to correlate that with before deciding for certain. If the numbers are 32-bit then the range could mean 0x00000000 to 0x0000ffff.

    I think what is meant by "weight" is the relevant power of 10. So 1234 means 1*1000+2*100+3*10+4, and that's what it means by multiply and add, and the resulting value of 1234 in the relevant register will contain the value which you can then represent in binary with the method you've outlined.

    I'm not clear what is meant by a division method, maybe something like:
    while binvalue:
    store digit (binvalue%10)+0x30
    binvalue/=10
    end while
     

Share This Page