I'm having difficulty understanding the purpose of the Valulng, Vallng, Valuint, Valint keywords. I understand what they do, but I don't understand why they go about in the way that they do. Specifically, I don't understand why a hexadecimal string is expected to have a prefix of "&H". Why not allow for the accepted standard notation, namely a prefix of "0x" or a suffix of "h"?
I have an application which accepts hexadecimal strings in the form 0x1234 and then converts them to ulongints. In order for this to work, I need to use Mid to change the first two characters of the string. This begs the question, are there any circumstances where external data are formatted with FB's hex notation? As for an FB hex string generated by the program, I can't see why one would need to subsequently convert it to its original numeric value.
Valulng, Vallng, Valuint, Valint hex notation
Re: Valulng, Vallng, Valuint, Valint hex notation
The "standard notation" for BASIC is the &H prefix. MSX BASIC, QuickBASIC, Visual Basic, PowerBASIC and FreeBASIC all prefix hexadecimal numbers with &H.fzabkar wrote:I'm having difficulty understanding the purpose of the Valulng, Vallng, Valuint, Valint keywords. I understand what they do, but I don't understand why they go about in the way that they do. Specifically, I don't understand why a hexadecimal string is expected to have a prefix of "&H". Why not allow for the accepted standard notation, namely a prefix of "0x" or a suffix of "h"?
I have an application which accepts hexadecimal strings in the form 0x1234 and then converts them to ulongints. In order for this to work, I need to use Mid to change the first two characters of the string. This begs the question, are there any circumstances where external data are formatted with FB's hex notation? As for an FB hex string generated by the program, I can't see why one would need to subsequently convert it to its original numeric value.
Re: Valulng, Vallng, Valuint, Valint hex notation
Perhaps I didn't explain myself very well.
I understand that "&H" is standard BASIC notation. However, I ask myself, under what circumstances would my program execute the following code?
Does it make sense for a string such as "&H1234" to be input from a file? What kind of real file would store hex data in Basic notation? I can't think of any, so there is unlikely to be any use for the following code when dealing with hex/binary/octal data:
If the string doesn't come from an external source, then it must be generated internally by the program. This then begs the question, does it make sense for the string to be generated within the Basic program and then converted back again within the same program? If the program can generate the string, then it can also directly generate the ulongint ...
I understand that "&H" is standard BASIC notation. However, I ask myself, under what circumstances would my program execute the following code?
Code: Select all
ulivar = Valulng( "&H1234")
Code: Select all
Line Input #inf, strgvar
uliVar = Valulng( strgvar )
Code: Select all
ulivar1 = &H1234
strgvar = Hex( ulivar1 )
...
ulivar2 = Valulng( strgvar )
Re: Valulng, Vallng, Valuint, Valint hex notation
fzabkar wrote:I understand that "&H" is standard BASIC notation. However, I ask myself, under what circumstances would my program execute the following code?
Why is it that some people make "simple things" unnecessarily complex?fzabkar wrote:Does it make sense for a string such as "&H1234" to be input from a file?
Let's face it all those data-type conversions (especially to/from file) are not really needed.
Store decimal values to file and thereafter, retrieve them as such again.
All that's required is a (specified) delimiter between two values, in order to separate them (CSV style file).
(typically uses either comma ',' or semi-colon ';' as delimiter-character)
Btw. "0x" notation is C/C++ not BASIC.
Re: Valulng, Vallng, Valuint, Valint hex notation
There is another thing that I'd like to bring to attention:
the 'more recent' conversion functions of FB are (not as misleading as the val... stuff):
unsigned:
CUByte()
CUShort()
CULng()
CULngInt("1234567890") and all the others Cxxxx types (have a look in the doc's).
They make use of VAL... conversions but, behind the scenes.
the 'more recent' conversion functions of FB are (not as misleading as the val... stuff):
unsigned:
CUByte()
CUShort()
CULng()
CULngInt("1234567890") and all the others Cxxxx types (have a look in the doc's).
They make use of VAL... conversions but, behind the scenes.
Re: Valulng, Vallng, Valuint, Valint hex notation
I'm converting a ddrescue map file into another format.
Ddrescue produces a human readable log (map), eg ...
Ddrescue produces a human readable log (map), eg ...
Code: Select all
# Mapfile. Created by GNU ddrescue version 1.25
# Command line: ddrescue -d -c18 /dev/fd0 fdimage mapfile
# Start time: 2015-07-21 09:37:44
# Current time: 2015-07-21 09:38:19
# Copying non-tried blocks... Pass 1 (forwards)
# current_pos current_status current_pass
0x00120000 ? 1
# pos size status
0x00000000 0x00117000 +
0x00117000 0x00000200 -
0x00117200 0x00001000 /
0x00118200 0x00007E00 *
0x00120000 0x00048000 ?
Re: Valulng, Vallng, Valuint, Valint hex notation
In case you can find an external source that uses &H1234 notation, let me know, maybe I can add it to the formats that Val() recognises.
P.S. That was easy, just 20 minutes of work:Output:
P.S. That was easy, just 20 minutes of work:
Code: Select all
include \masm32\MasmBasic\MasmBasic.inc
Init
Print Str$("&H075BCD15\t%i\n", Val("&H075BCD15")) ; BASIC: &H...
Print Str$("&h075BCD15\t%i\n", Val("&h075BCD15")) ; BASIC: &h...
Print Str$("0x075BCD15\t%i\n", Val("0x075BCD15")) ; C/C++: 0x...
Print Str$("$075BCD15\t%i\n", Val("$075BCD15")) ; C/C++: $...
Print Str$("075BCD15h\t%i\n", Val("075BCD15h")) ; Masm: ...h
EndOfCode
Code: Select all
&H075BCD15 123456789
&h075BCD15 123456789
0x075BCD15 123456789
$075BCD15 123456789
075BCD15h 123456789