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


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

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

Message-ID <4E47FC50.5020903@yahoo.co.uk> (permalink)
Date 2011-08-14 18:48 +0200
From Rick Murray <heyrickmail-usenet@yahoo.co.uk>
Newsgroups comp.sys.acorn.programmer
Subject Re: Is there an equivalent piece of BASIC that will return the size (in bits) of a number.
References <d515591d-7af9-4e9d-afb9-110bdc721e53@a31g2000vbt.googlegroups.com>
Organization les newsgroups par Orange

Show all headers | View raw


On 14/08/2011 13:39, Gazza wrote:

> sizeof(<num>) function. This returns the number of bits taken up by
> the number currently stored, NOT the memory footprint of the variable.

...but the memory footprint is exactly what sizeof() returns!


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

Try it on C, you'd get 32 every time. ;-)


For what you are wanting, you want to know the base 2 table, so some 
code such as:
   DEF FNsizeof(n%)
     IF (n% <   2) : =1
     IF (n% <   4) : =2
     IF (n% <   8) : =3
     IF (n% <  16) : =4
     IF (n% <  32) : =5
     IF (n% <  64) : =6
     IF (n% < 128) : =7
   =8

There's probably a sexy single-line version that can cater for up to 32 
bit, but maths isn't my strong point...


Best wishes,

Rick.

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