|
SwapByteOrder | ||||||||
Result = SwapByteOrder(Value) | ||||||||
Parameters: Value = The value whose byte order you want to swap |
||||||||
Returns: Result |
||||||||
SwapByteOrder splits an 32bit integer value into 4 bytes, reverses the order of these bytes and returns the result as an integer value. For example the binary representation of the decimal value 16909320 is
Now we split this value into 4 bytes named A, B, C and D
and change the order to D, C, B and A
So the binary equivalent of what SwapByteOrder(16909320) returns would be
which is decimal 134480385. FACTS: * SwapByteOrder is often used when reading / writing data. Something you might not be aware is that different computers / platforms have different ideas about how that same data should be stored. For example when we write Integers to memory on PC (Intel/AMD) platforms the bytes are stored lowest to highest byte. Where as other platforms store integers highest to lowest. Often called Motorola format. So If you read a file expecting the data within it to be stored in Intel/Amd format, then you can sometimes be surprised. If that occurs you'd use SwapByteOrder to flip the bytes. Mini Tutorial #1: Showing the effect of SwapByteOrder
This example would output.
Mini Tutorial #2: This example writes an integer to memory then shows the byte order of how the data is stored in memory. It then flips the bytes within the integer and display the results.
This example would output.
|
Related Info: | LSL32 | LSR32 | Operators | PeekInt | ROL32 | ROR32 | SwapLowBytes | SwapWordOrder : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |