Author Topic: Simple Question Concerning Numbers  (Read 4386 times)

0 Members and 1 Guest are viewing this topic.

Offline Maxwelldoggums

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +0/-0
    • View Profile
Simple Question Concerning Numbers
« on: June 06, 2010, 10:09:12 am »
Hey, needless to say I'm new here, and I just started using AXE. I absolutely love it, but there's something I just can't seem to wrap my head around.

I would like to store a list in memory using the Δlist command, however, I would like to give it negative numbers as values. I've never worked with this kind of system before, so using unsigned integers is new to me... How would I say...

:Δlist( -5 )?

would that be written

:Δlist( 32772 )?

Thanks,
-Andrew

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Simple Question Concerning Numbers
« Reply #1 on: June 06, 2010, 11:16:55 am »
Quote
wrap my head around.
Haha, funny.

For unsigned 1-byte numbers, you can count up to 255, then it wraps back to 0 (i.e., 0 would be the same as 256). If it were signed, though, since the range is only from -128 to 127, it counts to 127, then wraps down to -128. Since it really makes no difference to the calculator anyway (signed and unsigned are just two ways for a human to read), this means that -128 is the same as 128, -127 is the same as 129, -126 is the same as -130, etc.

For 2-byte numbers, it's similar, but instead of wrapping signed numbers at 126, 127, -128, etc., it wraps at 32767 to -32768. Since unsigned numbers would just continue on until 65535 (which would be -1 in signed notation), -5 is the same as 65531.

Basically, if you want to find the signed representation of any 2-byte integer above 32767 (or 1-byte integer above 127), just subtract 65536 (or 256, respectively).

This is only some information regarding signed numbers. Don't really know how to implement it in Axe, but wouldn't you need an r for 2-byte numbers with ΔList(?
« Last Edit: June 06, 2010, 11:20:45 am by Deep Thought »




SirCmpwn

  • Guest
Re: Simple Question Concerning Numbers
« Reply #2 on: June 06, 2010, 11:20:01 am »
Yes.  If you wanted to do a ΔList with 2 byte numbers, you have to do this:
ΔList(2r,4,76r,-2r
In which case, 2 and 76 would take up 2 bytes.  -2 would take up two bytes, and is the signed representation of -2.
« Last Edit: June 06, 2010, 11:38:36 am by Mr_Coding_Knight »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Simple Question Concerning Numbers
« Reply #3 on: June 06, 2010, 01:11:48 pm »
It depends on how big you want the range of numbers.  If you only need between -128 and 127 then you can just use deltalist(-1,-2,-3,...).  But when you read from the list, just make sure you use the int(data) command instead of {data} to keep the sign intact.

If on the other hand, you need the full range, then you need to store them all as 2 byte numbers using the "r".  Make sure if its 2 bytes per number, that you transverse the list 2 bytes at a time.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Simple Question Concerning Numbers
« Reply #4 on: June 06, 2010, 01:18:15 pm »
Yes.  If you wanted to do a ΔList with 2 byte numbers, you have to do this:
ΔList(2r,4,76r,-2r
In which case, 2 and 76 would take up 2 bytes.  -2 would take up two bytes, and is the signed representation of -2.

So Axe allows mixing 1- and 2-byte data?




Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Simple Question Concerning Numbers
« Reply #5 on: June 06, 2010, 01:23:04 pm »
but you have to remember what is what, because they aren't all, say, 2-byte aligned.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Simple Question Concerning Numbers
« Reply #6 on: June 06, 2010, 04:06:55 pm »
:Δlist( -5 )?

would that be written

:Δlist( 32772 )?
Hi and welcome here!

The result would actually be 65530 if you used 2 bytes integers and 250 if you used 1 byte integers

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Simple Question Concerning Numbers
« Reply #7 on: June 06, 2010, 07:00:38 pm »
:Δlist( -5 )?

would that be written

:Δlist( 32772 )?
Hi and welcome here!

The result would actually be 65530 if you used 2 bytes integers and 250 if you used 1 byte integers

Haven't really played around with Axe much yet, but after reading the documentation, I was under the impression that Axe used two's complement. Wouldn't it be 65531 and 251?
« Last Edit: June 06, 2010, 07:01:57 pm by Deep Thought »




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Simple Question Concerning Numbers
« Reply #8 on: June 06, 2010, 09:45:56 pm »
Woops you're right, my bad x.x