Hexadecimal to Decimal

Post your Gambas programming questions here.
Post Reply
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Hexadecimal to Decimal

Post by cogier »

Print &HFFF Returns 4095
Print &HFFFF Returns -1 not 65535
Print &HFFFFF Returns 1048575

Am I missing something here?
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Hexadecimal to Decimal

Post by stevedee »

cogier wrote: Monday 15th February 2021 4:52pm Print &HFFF Returns 4095
Print &HFFFF Returns -1 not 65535
Print &HFFFFF Returns 1048575

Am I missing something here?
Try:-
Print &H00FFFF (Returns 65535)
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Hexadecimal to Decimal

Post by PJBlack »

Byte 0 … 255 1 Byte
Short -32.768 … +32.767 2 Bytes
Integer -2.147.483.648 … +2.147.483.647 4 Bytes
Long -9.223.372.036.854.775.808 … +9.223.372.036.854.775.807 8 Bytes

Print &HFFF nearest fitting data type = short -> Returns 4095
Print &HFFFF nearest fitting data type = short -> Returns -1 (which is correct)
Print &HFFFFF nearest fitting data type = integer -> Returns 1048575
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Hexadecimal to Decimal

Post by stevedee »

Yes, I think its a casting problem. Adding a trailing "&" seems to sort it out:-
&hffff&
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Hexadecimal to Decimal

Post by cogier »

Thanks, that extra '00' works but why?
Post Reply