[missing feature] Is there a postfix for unsigned 16-bit hex values ?

General FreeBASIC programming questions.
Post Reply
D.J.Peters
Posts: 8642
Joined: May 28, 2005 3:28
Contact:

[missing feature] Is there a postfix for unsigned 16-bit hex values ?

Post by D.J.Peters »

I know it exists unsigned 32-bit postfix "UL" e.g. &H81234UL but Is there a kind of 16-bit "US" also ?

something like: &H8123US

Joshy
Last edited by D.J.Peters on Jun 15, 2025 1:08, edited 1 time in total.
SARG
Posts: 1888
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Is there a postfix for unsigned 16bit hex values ?

Post by SARG »

D.J.Peters
Posts: 8642
Joined: May 28, 2005 3:28
Contact:

Re: Is there a postfix for unsigned 16bit hex values ?

Post by D.J.Peters »

SARG wrote: Jun 14, 2025 19:01No.
That's exactly what I didn't want to hear. :-)

Joshy
dodicat
Posts: 8267
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: [missing feature] Is there a postfix for unsigned 16-bit hex values ?

Post by dodicat »

Tag on US and smell the coffee?

Code: Select all


#cmdline "-w none"

#define US and 65535u

print &H81234UL
print &H81234ULUS
print cushort(&H81234UL)
print cast(ushort,&H81234UL)

sleep 
 
Berkeley
Posts: 115
Joined: Jun 08, 2024 15:03

Re: [missing feature] Is there a postfix for unsigned 16-bit hex values ?

Post by Berkeley »

What for ?

If you have

Code: Select all

DIM AS USHORT myval

myval=&H3B1
won't make any trouble. Perhaps if you assign a long value, it's cut to 16 bit. If you assign a short value to a long variable, the highbytes should be set to 0 automatically. You'd have to write into the memory directly to get "unwanted" results.

An to keep it safe, use

Code: Select all

myval=myval AND &HFFFF
to turn a ULONG value into a USHORT. For signed numbers better use the CAST operator. Curiously, the difference between signed and unsigned integers is a bigger problem.
Post Reply