"Sputnik" help  
Sputnik Help
CropToBytes(<value>, <byteCount>)

Description

Crops a value to a given byte count, dropping the excess bytes. The value will be converted to an unsigned 64-bit integer if it's not already.

Parameters

<value> The value to crop. It can be of any data type and will be converted to an unsigned 64-bit integer if necessary.
<byteCount> The number of bytes to keep in the cropped result.

Return Value

Success: Returns the cropped unsigned 64-bit integer.
Failure: Returns 0.

Remarks

The CropToBytes function takes a value of any data type and a byte count. It converts the value to an unsigned 64-bit integer if it's not already, and then keeps only the specified number of bytes from the original value, discarding any excess bytes. The function performs bitwise operations to mask out the unwanted bytes.

Related

Example

Example of usage:

my $v = @UInt64Max;
say CropToBytes($v, 8);
say CropToBytes($v, 7);
say CropToBytes($v, 6);
say CropToBytes($v, 5);
say CropToBytes($v, 4);
say CropToBytes($v, 3);
say CropToBytes($v, 1);
// PRINTS
// 18446744073709551615
// 72057594037927935
// 281474976710655
// 1099511627775
// 4294967295
// 16777215
// 65535
// 255

 


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