
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
MATHEMATICS
Understand hexadecimal numbers
I was working with IM today. I found some toolbox constants that I need. There is only one problem: they are hex values. How do I set up FB (1.0.3) to recognize those as Hex numbers? (I need to add them, like you would add attributes for a window... so I don't think strings would work...)
Just assign the constants hex values.
Example:
_myHexConstant = &10 'hex equiv of 16
Basically if you can do it in hex you can do it in decimal. If you assign the hex value to a variable it will be converted into decimal, but that doesn't change its value, just its representation. In other words, you could also convert the toolbox hex values into decimal and use them that way.
And if you are sending a value to something, you can still send it in decimal because its value (in octal, binary, decimal, hex, whatever) is still the same.
If that isn't what you mean then, I think I misread your question,
Yes. But, if IM lists constants in hex, isn't hex what the ToolBox expects if you use that constant? In other words, if you pass a decimal value (let's say 10) to a toolbox function that was expecting a hex value, couldn't bad stuff happen? (like your 10 (decimal) getting interpreted to 10 (hex)). Or, is the Toolbox smarter then that?
Are we talking about numbers or strings? If you are entering numbers, the computer knows them only in binary. FB converts all numeric entries into binary values, just as it does all FB commands. You tell FB what format you are giving it by using a "&" prefix to indicate hex, omit it to indicate decimal. As long as you remember to do that (and make sure you know which you are using) you don't have to worry about it beyond that.
All HEX$ and BIN$ do is convert those binary values into appropriate character representations. FB, by default, does the same thing to show decimal numbers without your specifically asking for it.
Hope that adds some clarity.
The Toolbox itself is "language-independent," and doesn't care what the constant looked like (i.e., what "base" it was in) when you typed it into your language editor (such as FB's editor). The real question is whether the compiler/assembler that converts it from text into actual bits in memory is smart enough to do that conversion right. FB is smart enough, if you give it some help. If, in your source code, you precede the digits with "&" (or in some cases "$") then FB does a hex-to-binary conversion before feeding the number to the Toolbox. If you don't put any special symbol before the digits, then FB does a decimal-to-binary conversion before feeding the number to the Toolbox.
|