Code archives/Networking/IntToStr$ - StrToInt%

This code has been declared by its author to be Public Domain code.

Download source code

IntToStr$ - StrToInt% by SurreaL2001
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.
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.

Code Archives Forum