"Sputnik" help  
Sputnik Help
SizeCode(<size>)

Description

Calculates the size code based on the specified size.

Parameters

<value> The size in bytes for which the size code is to be determined.

Return Value

Success: Returns the size code for the specified size.
Failure: Returns null.

Remarks

The SizeCode function calculates the size code based on the specified size in bytes. The size code represents the code associated with a specific size and is used in other functions for further processing.

The internal implementation of the function checks if the specified size is a power of two using a power of two checker. If the size is not a power of two, the function returns 0 to indicate a failure. If the size is a power of two, the function iteratively right-shifts the size by 1 until it becomes 0, counting the number of iterations. The final count represents the size code.

If the specified size is not a valid size (not a power of two), the function returns 0 to indicate the failure.

Related

Example

Example of usage:

say "1 Byte(s) to SizeCode = " . SizeCode(1);
say "2 Byte(s) to SizeCode = " . SizeCode(2);
say "3 Byte(s) to SizeCode = " . SizeCode(3);
say "4 Byte(s) to SizeCode = " . SizeCode(4);
say "5 Byte(s) to SizeCode = " . SizeCode(5);
say "6 Byte(s) to SizeCode = " . SizeCode(6);
say "7 Byte(s) to SizeCode = " . SizeCode(7);
say "8 Byte(s) to SizeCode = " . SizeCode(8);

// PRINTS
// 1 Byte(s) to SizeCode = 0
// 2 Byte(s) to SizeCode = 1
// 3 Byte(s) to SizeCode = 0
// 4 Byte(s) to SizeCode = 2
// 5 Byte(s) to SizeCode = 0
// 6 Byte(s) to SizeCode = 0
// 7 Byte(s) to SizeCode = 0
// 8 Byte(s) to SizeCode = 3

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org