October 17, 2021, 10:21:00

Author Topic: [bmx] Determining size of data type by BlitzSupport [ 1+ years ago ]  (Read 689 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Determining size of data type
Author : BlitzSupport
Posted : 1+ years ago

Description : Some time ago, I made a Blitz interface for Jari Komppa's <a href="http://sol.gfxile.net/escapi/index.html" target="_blank">ESCAPI[/url] webcam library, <a href="codearcs4050.html?code=1899" target="_blank">here in the Code Archives[/url].

Anyway, I just accidentally found a reference I made ages ago to <a href="http://sol.gfxile.net/oldernews2010.html" target="_blank">this page[/url] 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:

<div class="quote">
how to find the size of of any data type using bit manipulations

Set to 1, shift left until zero."
 
</div>

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...


Code :
Code: BlitzMax
  1. variable:Long = 1
  2.  
  3. Repeat
  4.  
  5.         variable = variable Shl 1
  6.        
  7.         count = count + 1
  8.        
  9. Until variable = 0
  10.  
  11. Print count


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal