i have a byte array question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djones
    New Member
    • Jan 2010
    • 1

    i have a byte array question

    I have a byte array that contains a string like 1c1ba2... etc
    I would like to print out 5 digits. so for example:

    1c = 28
    1b = 27
    a2 = 162

    my output needs to be five digits long so 28271.

    I thought about using printf but it seems like when i use it it reports the count
    its shows 1 more than there should be

    so 1b = 27 but printf report 3. does printf do some kind of padding?
    the reason i was looking at counts was to limit my output to 5. I am not sure how else i can do this.

    the goal is to print 5 digits out of that byte array.

    thank you for your help.
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    You have just about solved it.
    within a while loop:
    1. Combine each successive pair of array elements into a hex integer format and convert that format to decimal. dec_int == this value.
    2. Load each to a new array.
    Within a loop:
    3. Print these values out making sure that if the first value >99, the second value <99 by dividing by 10 or 100, Use a counting variable to ensure that the number of digits in each combination does not exceed 5.

    Comment

    • MrPickle
      New Member
      • Jul 2008
      • 100

      #3
      I believe the extra character you are seeing is the null terminator '\0'. This is to signify the end of the string.

      Comment

      Working...