Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #618

Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number.

From Michael Gerbracht <nospam@cityweb.de>
Subject Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number.
Newsgroups comp.sys.acorn.programmer
Date 2011-08-14 14:17 +0100
Message-ID <5202a4a9aanospam@cityweb.de> (permalink)
References <d515591d-7af9-4e9d-afb9-110bdc721e53@a31g2000vbt.googlegroups.com>
Organization None

Show all headers | View raw


In article
<d515591d-7af9-4e9d-afb9-110bdc721e53@a31g2000vbt.googlegroups.com>,
   Gazza <usenet@garethlock.com> wrote:
> I'm looking for a routine that performs the equivalent of C/C++
> sizeof(<num>) function. This returns the number of bits taken up by
> the number currently stored, NOT the memory footprint of the variable.
> So...

> Dim j as INT32
> Dim k as INT32
> j=2
> k=sizeof(j)

> Variable "k" here would return 2, NOT 32. (To express 2 in binary
> requires 2 bits.)

If I understand you correctly you would like to know how many bits are
required to store e.g. the number 15. Just calculate ln(15)/ln(2) and then
round to the next higher number. Here: ln(15)/ln(2) = 3.91, so you need 4
bits to store the number.

Michael

-- 
Please replace nospam by m.gerbracht when replying by e-mail

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Gazza <usenet@garethlock.com> - 2011-08-14 04:39 -0700
  Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Michael Gerbracht <nospam@cityweb.de> - 2011-08-14 14:17 +0100
  Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Matthew Phillips <spam2011m@yahoo.co.uk> - 2011-08-14 15:02 +0100
  Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. druck <news@druck.org.uk> - 2011-08-14 15:23 +0100
    Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Gazza <usenet@garethlock.com> - 2011-08-14 08:43 -0700
    Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. cferris@freeRemoveuk.com.invalid - 2011-08-15 09:24 +0100
      Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. druck <news@druck.org.uk> - 2011-08-15 10:04 +0100
        Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Matthew Phillips <spam2011m@yahoo.co.uk> - 2011-08-15 20:07 +0100
  Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-08-14 18:48 +0200
    Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Stewart Brodie <stewart.brodie@ntlworld.com> - 2011-08-14 18:27 +0100
    Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. jeff <jeffrey.a.doggett@gmail.com> - 2011-08-16 01:00 -0700
      Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number. Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-08-16 18:39 +0200

csiph-web