[bb] IntToStr$ - StrToInt% by SurreaL [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : IntToStr$ - StrToInt%
Author : SurreaL
Posted : 1+ years ago

Description : I saw Halo's functions which converted an integer to a string and back again, and thought they were useful in theory, but could be optimized a bit. Here is my result.

Code :
Code (blitzbasic) Select
Function IntToStr$(num%, strlen% = 4)
st$ = Chr$(num And 255)
For shiftin = 1 To (strlen - 1)
st$ = st$ + Chr$(num Shr (8 * shiftin))
Next
Return st$
End Function

Function StrToInt%(st$)
For shiftin = 0 To (Len (st$) - 1)
num = num Or (Asc (Mid$ (st$, shiftin + 1, 1)) Shl shiftin * 8)
Next
Return num
End Function


Comments : none...