Hi all,
I need to write ascii chars.
Whitch library and whitch code can I use?
Thanks in advance
M.
I need to write ascii chars.
Whitch library and whitch code can I use?
Thanks in advance
M.
' Convert a 32-bit integer to four ASCII characters
Sub writeChars(value As Int)
Dim i, k As Int
For i = 0 To 3
k = Bit.And(value, 0xFF)
Log(Chr(k))
value = Bit.ShiftRight(value, 8)
Next
End Sub
I learn something new every day - always been so focused on translating Unicode characters 0..255 to single bytes, never even noticed there was the ASCII mapping :-/.GetBytes("ASCII")
If we step back a level so that we can see the forest for the trees... what are you actually trying to do, like: what is the end aim?I need to write a thing like this: "Try to write chr"
View attachment 82985
Dim Translation As String = MarcoStrikesAgain("Try to write chr")
Log(Translation)
'pads a string with spaces at start, to length L, returns first L characters
Sub LeftPad(S As String, L As Int) As String
Do While S.Length < L
S = " " & S
Loop
Return S.SubString2(0, L)
End Sub
'translates string to match example layout structure
Sub MarcoStrikesAgain(StringToTranslate As String) As String
Dim Index As Int = 0
Dim NumOnLine As Int = 0
Dim OutputString As String
For I = 0 To StringToTranslate.Length - 1
If NumOnLine = 0 Then
If Index = 0 Then
OutputString = OutputString & "Index Bit 31-24 Bit 23-16 Bit 15-8 Bit 7-0" & CRLF
End If
Index = Index + 1
OutputString = OutputString & LeftPad(Index, 5)
End If
OutputString = OutputString & LeftPad(StringToTranslate.CharAt(I), 11)
NumOnLine = NumOnLine + 1
If NumOnLine >= 4 Then
OutputString = OutputString & CRLF
NumOnLine = 0
End If
Next
If NumOnLine > 0 Then
OutputString = OutputString & CRLF
NumOnLine = 0
End If
Return OutputString
End Sub
Index Bit 31-24 Bit 23-16 Bit 15-8 Bit 7-0
1 T r y
2 t o w
3 r i t e
4 c h r