Am I comparing hexidecimal values in tcl properly?Why does comparing strings using either '==' or 'is' sometimes produce a different result?What is the rationale for all comparisons returning false for IEEE754 NaN values?In bash, how can I check if a string begins with some value?How to compare dates in Java?Comparing date part only without comparing time in JavaScriptCompare two files in Visual StudioInstantiation error when comparing two different valuespython comparing integers in conditionsHow python compares nested sequencescomparison condition in case statement

What are the unintended or dangerous consequences of allowing spells that target and damage creatures to also target and damage objects?

noalign caused by multirow and colors

Print "N NE E SE S SW W NW"

Can there be absolute velocity?

How to write a convincing religious myth?

How can one's career as a reviewer be ended?

Should I put programming books I wrote a few years ago on my resume?

Analogy between an unknown in an argument, and a contradiction in the principle of explosion

I've been given a project I can't complete, what should I do?

How and why do references in academic papers work?

To what extent do precedents in Westminster systems apply in other countries that use it?

Remove border lines of SRTM tiles rendered as hillshade

bash vs. zsh: What are the practical differences?

Flight compensation with agent

What would be the way to say "just saying" in German? (Not the literal translation)

As easy as Three, Two, One... How fast can you go from Five to Four?

Why is Na5 not played in this line of the French Defense, Advance Variation?

empApi with Lightning Web Components?

If I had a daughter who (is/were/was) cute, I would be very happy

Should I refuse to be named as co-author of a low quality paper?

Is Dumbledore a human lie detector?

How can I remove material from this wood beam?

The origin of the Russian proverb about two hares

The significance of kelvin as a unit of absolute temperature



Am I comparing hexidecimal values in tcl properly?


Why does comparing strings using either '==' or 'is' sometimes produce a different result?What is the rationale for all comparisons returning false for IEEE754 NaN values?In bash, how can I check if a string begins with some value?How to compare dates in Java?Comparing date part only without comparing time in JavaScriptCompare two files in Visual StudioInstantiation error when comparing two different valuespython comparing integers in conditionsHow python compares nested sequencescomparison condition in case statement






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am doing some simple hex comparison in an if statement.



0x7843E0 is greater than 0x780000 but the code below doesn't output anything.



if "780000" <= "7843E0" 
puts "True!"

>>


Omitting the trailing 0 works fine however.



if "780000" <= "7843E" 
puts "True!"

>>> True!


There must be something wrong with the trailing 0 but I don't understand what it is. Any ideas?










share|improve this question




























    0















    I am doing some simple hex comparison in an if statement.



    0x7843E0 is greater than 0x780000 but the code below doesn't output anything.



    if "780000" <= "7843E0" 
    puts "True!"

    >>


    Omitting the trailing 0 works fine however.



    if "780000" <= "7843E" 
    puts "True!"

    >>> True!


    There must be something wrong with the trailing 0 but I don't understand what it is. Any ideas?










    share|improve this question
























      0












      0








      0








      I am doing some simple hex comparison in an if statement.



      0x7843E0 is greater than 0x780000 but the code below doesn't output anything.



      if "780000" <= "7843E0" 
      puts "True!"

      >>


      Omitting the trailing 0 works fine however.



      if "780000" <= "7843E" 
      puts "True!"

      >>> True!


      There must be something wrong with the trailing 0 but I don't understand what it is. Any ideas?










      share|improve this question














      I am doing some simple hex comparison in an if statement.



      0x7843E0 is greater than 0x780000 but the code below doesn't output anything.



      if "780000" <= "7843E0" 
      puts "True!"

      >>


      Omitting the trailing 0 works fine however.



      if "780000" <= "7843E" 
      puts "True!"

      >>> True!


      There must be something wrong with the trailing 0 but I don't understand what it is. Any ideas?







      comparison tcl






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 21:50









      user1224478user1224478

      871413




      871413






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You're having problems with the way the expr command parses numbers. (The rest of Tcl is more relaxed about this.) The issue is that:




          • "780000" gets interpreted as a decimal integer.


          • "7843E0" gets interpreted as a double precision floating point number. (Compare with 1.2e10; the number parser thinks it is fitting the same sort of pattern.)


          • "780000" gets interpreted as a decimal integer.


          • "7843E" gets interpreted as a non-numeric string (a fallback because no numeric interpretation is legal).

          The <= operator will happily compare two numbers if they're both numbers, or two strings if at least one of the parameters to it is non-numeric. (Yes, this does make for weird semantics occasionally.) Moreover, he expr command is eager to interpret values as numbers if it possibly can, but it still has Tcl's syntactic rules for what actually is numeric, and what type of numeric those things are. When you don't stick to the rules, it gets a bit odd.



          To get a value interpreted as hexadecimal, you have to either prefix its string representation with 0x (e.g., 0x7843E0) or force things with a command such as scan with %x:



          scan "780000" %x a
          scan "7843E0" %x b
          if $a <= $b
          puts "True"



          Forcing interpretations with scan is considered to be one of the best ways of dealing with this, as that only writes canonical values into variables. (If you'd been wanting to handle octal numbers, or were wanting to really always be decimal, you'd use %o and %d respectively; %f is for floating-point numbers.)



          Finally, if you're really comparing values as strings with normal ASCII-like rules, look at string compare instead of using <= directly.



          if [string compare $input1 $input2] <= 0 
          ...






          share|improve this answer























          • Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

            – Joey Mallone
            Mar 26 at 12:37












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328922%2fam-i-comparing-hexidecimal-values-in-tcl-properly%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You're having problems with the way the expr command parses numbers. (The rest of Tcl is more relaxed about this.) The issue is that:




          • "780000" gets interpreted as a decimal integer.


          • "7843E0" gets interpreted as a double precision floating point number. (Compare with 1.2e10; the number parser thinks it is fitting the same sort of pattern.)


          • "780000" gets interpreted as a decimal integer.


          • "7843E" gets interpreted as a non-numeric string (a fallback because no numeric interpretation is legal).

          The <= operator will happily compare two numbers if they're both numbers, or two strings if at least one of the parameters to it is non-numeric. (Yes, this does make for weird semantics occasionally.) Moreover, he expr command is eager to interpret values as numbers if it possibly can, but it still has Tcl's syntactic rules for what actually is numeric, and what type of numeric those things are. When you don't stick to the rules, it gets a bit odd.



          To get a value interpreted as hexadecimal, you have to either prefix its string representation with 0x (e.g., 0x7843E0) or force things with a command such as scan with %x:



          scan "780000" %x a
          scan "7843E0" %x b
          if $a <= $b
          puts "True"



          Forcing interpretations with scan is considered to be one of the best ways of dealing with this, as that only writes canonical values into variables. (If you'd been wanting to handle octal numbers, or were wanting to really always be decimal, you'd use %o and %d respectively; %f is for floating-point numbers.)



          Finally, if you're really comparing values as strings with normal ASCII-like rules, look at string compare instead of using <= directly.



          if [string compare $input1 $input2] <= 0 
          ...






          share|improve this answer























          • Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

            – Joey Mallone
            Mar 26 at 12:37
















          2














          You're having problems with the way the expr command parses numbers. (The rest of Tcl is more relaxed about this.) The issue is that:




          • "780000" gets interpreted as a decimal integer.


          • "7843E0" gets interpreted as a double precision floating point number. (Compare with 1.2e10; the number parser thinks it is fitting the same sort of pattern.)


          • "780000" gets interpreted as a decimal integer.


          • "7843E" gets interpreted as a non-numeric string (a fallback because no numeric interpretation is legal).

          The <= operator will happily compare two numbers if they're both numbers, or two strings if at least one of the parameters to it is non-numeric. (Yes, this does make for weird semantics occasionally.) Moreover, he expr command is eager to interpret values as numbers if it possibly can, but it still has Tcl's syntactic rules for what actually is numeric, and what type of numeric those things are. When you don't stick to the rules, it gets a bit odd.



          To get a value interpreted as hexadecimal, you have to either prefix its string representation with 0x (e.g., 0x7843E0) or force things with a command such as scan with %x:



          scan "780000" %x a
          scan "7843E0" %x b
          if $a <= $b
          puts "True"



          Forcing interpretations with scan is considered to be one of the best ways of dealing with this, as that only writes canonical values into variables. (If you'd been wanting to handle octal numbers, or were wanting to really always be decimal, you'd use %o and %d respectively; %f is for floating-point numbers.)



          Finally, if you're really comparing values as strings with normal ASCII-like rules, look at string compare instead of using <= directly.



          if [string compare $input1 $input2] <= 0 
          ...






          share|improve this answer























          • Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

            – Joey Mallone
            Mar 26 at 12:37














          2












          2








          2







          You're having problems with the way the expr command parses numbers. (The rest of Tcl is more relaxed about this.) The issue is that:




          • "780000" gets interpreted as a decimal integer.


          • "7843E0" gets interpreted as a double precision floating point number. (Compare with 1.2e10; the number parser thinks it is fitting the same sort of pattern.)


          • "780000" gets interpreted as a decimal integer.


          • "7843E" gets interpreted as a non-numeric string (a fallback because no numeric interpretation is legal).

          The <= operator will happily compare two numbers if they're both numbers, or two strings if at least one of the parameters to it is non-numeric. (Yes, this does make for weird semantics occasionally.) Moreover, he expr command is eager to interpret values as numbers if it possibly can, but it still has Tcl's syntactic rules for what actually is numeric, and what type of numeric those things are. When you don't stick to the rules, it gets a bit odd.



          To get a value interpreted as hexadecimal, you have to either prefix its string representation with 0x (e.g., 0x7843E0) or force things with a command such as scan with %x:



          scan "780000" %x a
          scan "7843E0" %x b
          if $a <= $b
          puts "True"



          Forcing interpretations with scan is considered to be one of the best ways of dealing with this, as that only writes canonical values into variables. (If you'd been wanting to handle octal numbers, or were wanting to really always be decimal, you'd use %o and %d respectively; %f is for floating-point numbers.)



          Finally, if you're really comparing values as strings with normal ASCII-like rules, look at string compare instead of using <= directly.



          if [string compare $input1 $input2] <= 0 
          ...






          share|improve this answer













          You're having problems with the way the expr command parses numbers. (The rest of Tcl is more relaxed about this.) The issue is that:




          • "780000" gets interpreted as a decimal integer.


          • "7843E0" gets interpreted as a double precision floating point number. (Compare with 1.2e10; the number parser thinks it is fitting the same sort of pattern.)


          • "780000" gets interpreted as a decimal integer.


          • "7843E" gets interpreted as a non-numeric string (a fallback because no numeric interpretation is legal).

          The <= operator will happily compare two numbers if they're both numbers, or two strings if at least one of the parameters to it is non-numeric. (Yes, this does make for weird semantics occasionally.) Moreover, he expr command is eager to interpret values as numbers if it possibly can, but it still has Tcl's syntactic rules for what actually is numeric, and what type of numeric those things are. When you don't stick to the rules, it gets a bit odd.



          To get a value interpreted as hexadecimal, you have to either prefix its string representation with 0x (e.g., 0x7843E0) or force things with a command such as scan with %x:



          scan "780000" %x a
          scan "7843E0" %x b
          if $a <= $b
          puts "True"



          Forcing interpretations with scan is considered to be one of the best ways of dealing with this, as that only writes canonical values into variables. (If you'd been wanting to handle octal numbers, or were wanting to really always be decimal, you'd use %o and %d respectively; %f is for floating-point numbers.)



          Finally, if you're really comparing values as strings with normal ASCII-like rules, look at string compare instead of using <= directly.



          if [string compare $input1 $input2] <= 0 
          ...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 22:46









          Donal FellowsDonal Fellows

          105k15116182




          105k15116182












          • Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

            – Joey Mallone
            Mar 26 at 12:37


















          • Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

            – Joey Mallone
            Mar 26 at 12:37

















          Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

          – Joey Mallone
          Mar 26 at 12:37






          Nice answer, and I am not challenging or criticizing or anything (I am myself a N00b in the world of Tcl), but why not simply do if "0x780000" <= "0x7843E0". And exactly what is meant here by "canonical values"?

          – Joey Mallone
          Mar 26 at 12:37




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328922%2fam-i-comparing-hexidecimal-values-in-tcl-properly%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현