B4R Question Format number (tm1637 display)

Beja

Expert
Licensed User
Longtime User
Hi Folks,
I want to display leading leading zeros of the display module.. tm1637, along with the counter value. all my attempts didn't work.
 

emexes

Expert
Licensed User
Longtime User
Well, you could convert the number to decimal "manually" eg:

B4X:
Sub NumberToDigits(N As Int, NumDigits As Int) As Byte()
    Dim Digit(NumDigits) As Byte
   
    For I = 0 to Digit.Length - 1
        Dim N10 As Int = N / 10    
        Digit(I) = N - N10 * 10    ' + 0x30 if prefer ASCII '0' to '9'
        N = N10
    Next I
   
    Return Digit
End If
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Longtime User
I don't have a working B4R installed to test it with, but using B4J:

Test with:
For Burl = 1 To 10
    Dim TestNumber As Int = Rnd(0, 20000)
    Dim TestDigits() As Byte = NumberToDigits(TestNumber, 5)
    Log(TestNumber & TAB & TestDigits.As(List) & TAB & TestDigits(4) & TestDigits(3) & TestDigits(2) & TestDigits(1) & TestDigits(0))
Next
Log output:
Waiting for debugger to connect...
Program started.
6456    (ArrayList) [6, 5, 4, 6, 0]    06456
2394    (ArrayList) [4, 9, 3, 2, 0]    02394
763     (ArrayList) [3, 6, 7, 0, 0]    00763
7311    (ArrayList) [1, 1, 3, 7, 0]    07311
1239    (ArrayList) [9, 3, 2, 1, 0]    01239
12305   (ArrayList) [5, 0, 3, 2, 1]    12305
9706    (ArrayList) [6, 0, 7, 9, 0]    09706
4252    (ArrayList) [2, 5, 2, 4, 0]    04252
18038   (ArrayList) [8, 3, 0, 8, 1]    18038
10587   (ArrayList) [7, 8, 5, 0, 1]    10587
Program terminated (StartMessageLoop was not called).
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thank you!
Will test this and report back
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…