Incrementing Help


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78

    Post Incrementing Help

    Hi Forum, I know this is quite a simple problem but I am having a hard time trying to figure it out.

    How do I increment a counter variable in HEX?

    Counter = Counter + 1 ' this is what I normally do to increment a variable

    I assume that if I do something like this: that it will increment a variable in HEX

    Counter = Counter + $01


    Please correct me if I am wrong.


    Srig

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    incrementing is incremeting... adding is adding.

    there's no difference between a=a+1 against a=a+$1

    BUT if you want to add 10 in hex... yep a=a+$10

    only the modifier do a difference you can add hex, bin and decimal in the same formula too

    a=a+%00000111+$10+128
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2005
    Location
    Mandalay,Myanmar
    Posts
    9


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi Srigopal
    As value $01=01=%01,so what you write $01 or 01 is no difference.
    Compiler only know bit ,byte,word(data type). No more Hex or Dec.
    Mcus work only on binary.
    Your output (eg.serout,lcd out)can be binary,ASCII,Decimal and Hex.

    a.majid
    from_myanmar

  4. #4
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Post

    Now I have another question! What about the result. Will that be in hex form or a decimal representation of the hex value.

    for example lets say do the following

    counter = counter + $01 will the result in counter variable now have the HEX representation. or will it have the decimal representation.

    Also lets say I do the following

    PORTB = 128 'which is 1000000 in binary.
    this means that PORTB.7= 1 while the rest of the pins in portB = 0

    if I am not mistaken this is the same thing as saying PORTB = $80.

    So basically it does not matter if you are incrementing in HEX form or Decimal form because the output will eventually be converted back to binary form.

  5. #5
    peterwi's Avatar
    peterwi Guest


    Did you find this post helpful? Yes | No

    Default

    It doesn't matter how you "view" the number (hex, binary, or decimal), the value is still the same. So, adding one is the same, whether you add one "in hex" ($01) or "in binary" (%00000001) or "in decimal" (1). You still just have "a number".

    One thing that might help clarify this for you is to use the Calculator in Windows (if you're using Windows). Using the "Scientific View" (View >> Scientific), type in a number, then change the radio buttons to Hex, or Bin, or Dec. The VALUE hasn't changed, just the way it's represented.

Similar Threads

  1. Automatically incrementing version counter/variable
    By skimask in forum PBP Wish List
    Replies: 4
    Last Post: - 5th December 2008, 05:00
  2. Time delay by incrementing a variable using incoming pulse
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 28th October 2005, 03:50
  3. 32 bit addition
    By ice in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th May 2005, 11:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts