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.

Geek Culture / (Negative) Decimal to Hex Conversion

Author
Message
Killswitch
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: School damnit!! Let me go!! PLEASE!!!
Posted: 19th Oct 2005 21:33
Hey,

For the project I'm working on atm the moment I need to be able to convert Hex (and Oct) numbers into Decimal numbers, and vice versa. This is really easy for postivie numbers (the code for that is already done an dusted) but negative numbers are confusing me.

So, I could really do with some help. Can someone please explain how I can convert negative decimals to their correct hexadecimal or octal equivlants?

~It's a common mistake to make, the rules of the English langauge do not apply to insanity~
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 19th Oct 2005 22:22
To convert them it's basicly: 0xFFFFFFFF - (number - 1) IIRC.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 19th Oct 2005 23:02
Your talking about Signed / UnSigned numbers.
This basically works like this:

%xxxx xxx- = Your Value : 0 - 127
%---- ---x = Your Sign Value : 0 = - , 1 = +

So for example:

%1000 0001 = +64
%1000 0000 = -64

Althought I can't remember if C/C++/DBPro access the first or last bit as the Signed Value. Oh well I'm sure you can figure it out.

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 20th Oct 2005 01:48
you got it the other way around Raven. If the most-significant-bit is set, the number is negative. That and your numbers are backwards.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 20th Oct 2005 02:17


Like that? Although that doesn't work in DBP.
I don't usually mess around at this level cause C++/C# does it all for you, and converts.

Login to post a reply

Server time is: 2024-11-16 00:51:09
Your offset time is: 2024-11-16 00:51:09