32bit to long?

BlitzMax Forums/BlitzMax Programming/32bit to long?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

He wants to treat each character as a digit in a "base 256" number.

Here's my attempt. It assumes the string is four characters and each character code is in the range 0-255.
BlitzMax uses 16-bit unicode characters so this may not be true if your string was made in China.

Note the $FFFFFFFF:Long, just in case the result was a negative integer and got sign-extended to 64 bits.

BTL:Long = BytesToLong( Chr($FE) + Chr($DC) + Chr($BA) + Chr($98) )

Print
Print BTL
Print LongHex( BTL )

Function BytesToLong:Long( in$ )

	Local n:Int
	
	n = in[0]
	n = ( n Shl 8 ) | in[1]
	n = ( n Shl 8 ) | in[2]
	n = ( n Shl 8 ) | in[3]
			
	Return n & $FFFFFFFF:Long

End Function