EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

Differ between binary and hex in $sscanf

elektroda.net NewsGroups Forum Index - Verilog Language - Differ between binary and hex in $sscanf

Kenneth Brun Nielsen
Guest

Wed Jun 30, 2010 11:16 pm   



Is it possible to specify whether a given numeric string should be
interpreted as, say binary or hex type, by $sscanf?

E.g.

readLine = a register containing a string read from file.

if ($sscanf(readLine, "I2CWRITE %s %h", addrName, hexValue) == 2)
begin
// lookup addrName and
// write the hexadecimal sequence to the given address
end
else if ($sscanf(readLine, "I2CWRITE %s %b", addrName, binValue) == 2)
begin
// lookup addrName and
// write the binary sequence to the given address
end
else
$display( "Unknown command");

If readLine is the string "I2CWRITE TESTENABLE 01", $sscanf will
interpret "01" as both binary and hex. Does any syntax exist to
specify what type a given numeric value are of? For instance, if I
could write:
"I2CWRITE TESTENABLE 01b" in order to specify that the numeric value
01 should be interpreted as binary.

Obviously I could invent my own syntax and include it in the $sscanf
format line a'la
if ($sscanf(readLine, "I2CWRITE %s HEX %h", addrName, hexValue) == 2)
//
else if ($sscanf(readLine, "I2CWRITE %s BIN %b", addrName, binValue)
== 2)
, but:
1) I prefer a syntax without whitespaces (so the numeric value has
either a suffix or prefix)
2) I'd rather follow a predefined syntax, if it is already possible in
the $sscanf format.

Best regards,
Kenneth

Jonathan Bromley
Guest

Thu Jul 01, 2010 10:44 am   



Kenneth,

Quote:
Is it possible to specify whether a given numeric string should be
interpreted as, say binary or hex type, by $sscanf?

As far as I know there's no built-in way to parse the standard
Verilog number format (things like 4'b1001), which is a pity.
However, you could try something like this:

$sscanf(readLine, "'h%h", val)

and now the line of text is required to contain something
like 'h1001 (the 'h prefix becomes mandatory). I like the
idea that you can enforce the requirement to use something
that is also legal Verilog number syntax.

Dunno if this helps in your specific case.
--
Jonathan Bromley

Kenneth Brun Nielsen
Guest

Tue Jul 13, 2010 1:42 pm   



Hi Jonathan,

Quote:
Is it possible to specify whether a given numeric string should be
interpreted as, say binary or hex type, by $sscanf?

As far as I know there's no built-in way to parse the standard
Verilog number format (things like 4'b1001), which is a pity.
However, you could try something like this:

  $sscanf(readLine, "'h%h", val)

That might be a feasible solution in my case. I will try it soon.

Thanks for your valuable response.

Best regards,
Kenneth

elektroda.net NewsGroups Forum Index - Verilog Language - Differ between binary and hex in $sscanf

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony