Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Want to get the correct negative number , Please help

Author
Message
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 20th Apr 2012 15:40
Hello all fellow coders.
I have a problem the variable types of DarkBasic Proffesional.

I need to get the next negative result -512

0x00FE after turning 0xFE00

In the HEX Editor i use i get this :

00 as Shortint: 0
00FE as Word: 65024
00FE as Integer: -512

The integer is correct

The next value is done correct.

In the Hex Editor.

60 as Shortint: 96
6000 as Word: 96
6000 as Integer: 96

0x6000 after turning 0x0060

It gives the correct number of 96

I just can't get the negative number of -512
I have tried everything i can think off.

Any help will be greatly appreciated.

I have included some code.

Thanks Ron.




nr as integer
nr2 as integer

nr = 0xFE00 ` This must -512 !!
nr2 = 0x0060 ` This is correct 96

print nr
print nr2

do
loop
end


Programming is learning
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 20th Apr 2012 15:47
Here is the code.



Programming is learning
zeroSlave
14
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 20th Apr 2012 23:02


Would't this work? I'm not exactly sure why you are using hex so i'm not really sure what you are looking for.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Apr 2012 03:36 Edited at: 21st Apr 2012 03:40
An integer in DBP is a signed four byte integer so were you're declaring it as 0xFE00 (a short word value by the look) it should be something like 0xFFFFFE00.

EDIT: In DBP you can read a WORD value from a file and then cast it to an integer.

EDIT2: Although it does look like you cannot have a signed WORD...
Quote: "INTEGER Range : –2,147,483,648 to 2,147,483,647
REAL Range : 3.4E +/- 38 (7 digits)
BOOLEAN Range : 0 to 1
BYTE Range : 0 to 255
WORD Range : 0 to 65535
DWORD Range : 0 to 4,294,967,295
DOUBLE INTEGER Range : –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
DOUBLE FLOAT Range : 1.7E +/- 308 (15 digits)
"


Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 21st Apr 2012 08:10
zeroSlave and WLGfx thanks.

I am creating a map editor voor de good old doom games.
For me it's just to learn how ID software created IWAD and PWAD
directory structure.
IWAD = Internal WAD
PWAD = Patch WAD
WAD = Where's All the Data

The numbers are coord's (x,y)

I made a PWAD file myself to analyse.
Thats is why iám using the HEX Editor.
To check the data stored in the PWAD file

To read the coord data from the file i can't use the unsigned word.
Like WLGfx shows it's a positive variable. (0-65535)
it the only variable that is 16 bits.

x coord = 2 bytes and the y coord = 2 bytes.

I can't use the integer because it's 32 bits.

What i realy need is a signed integer.
but then one that is 16 bits.

Or a way to convert the number so it is giving me the correct -512.

if you have any questions please do.

Thanks Ron.

Programming is learning
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Apr 2012 15:20
A bit of psuedo code, but it's an idea of casting a WORD to an integer:


Fingers crossed that'll fix the casting...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 21st Apr 2012 17:17
WLGfx you are the best

Thank's to you i have created a function with your code.

You helped me a lot thank's

Cheers Ron.



Programming is learning
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 21st Apr 2012 17:42
I have posted the function code on the codebase also.
I hope that it will be off good use for people.

Programming is learning
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 21st Apr 2012 17:56
Here is the code that make it clear what i wanted to do.



Cheers Ron

Programming is learning
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 21st Apr 2012 18:05 Edited at: 21st Apr 2012 18:14
The function could be easier like this:



No probs RonsWare and have a beer for me too...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 21st Apr 2012 18:50
Your are right

I put the line in the code.

Thank's again WLGfx.

Cheers Ron.

Programming is learning

Login to post a reply

Server time is: 2024-05-17 19:15:31
Your offset time is: 2024-05-17 19:15:31