Code archives/Algorithms/Determining size of data type

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

Download source code

Determining size of data type by BlitzSupport2011
Some time ago, I made a Blitz interface for Jari Komppa's ESCAPI webcam library, here in the Code Archives.

Anyway, I just accidentally found a reference I made ages ago to this page of Jari's and tried out his impressively succint explanation of how to determine the size of a (numerical) data type, the total text of which is:


how to find the size of of any data type using bit manipulations

Set to 1, shift left until zero."



I tried it, and, well, it worked! No idea what use it might have, but change the type to Int and it'll return 32 bits instead of 64, or 16 bits for a Short type, 8 bits for a Byte, etc...

Posted just for the record...
variable:Long = 1

Repeat

	variable = variable Shl 1
	
	count = count + 1
	
Until variable = 0

Print count

Comments

None.

Code Archives Forum