According to this table, the degree symbol corresponds to extended ASCII code 0xB0 (decimal 176).Does anyone here knows how to display the 'degree' symbol in a string (C, C#, Java,...)? e.g. To display 22 degree celsuis, I want to display it this way: 22 0C (Note the symbol is not displayed properly here)
Yes! it works fine.According to this table, the degree symbol corresponds to extended ASCII code 0xB0 (decimal 176).
Yeah but no! I meant in code so I did something like this: string FahrenheitValue = String.Format("{0} \u00B0C = {1} \u00B0F", CelsiusValue, convertCelsiusToFahrenheit(CelsiusValue));Straight from my uppermost - leftmost lower case key: º
Typing Alt+0176, I get the same: °
Now I see, reading the John's post below that I failed to include the ASCII "°" expresion which is what you were asking for. Excuse moi!Yeah but no! I meant in code so I did something like this: string FahrenheitValue = String.Format("{0} \u00B0C = {1} \u00B0F", CelsiusValue, convertCelsiusToFahrenheit(CelsiusValue));
Thanks anyway as your Alt+0176 would be useful in word or Notepad.
Eric.
Not in any portable way. You have a couple of issue -- first is representing it to the compiler. To use the single-quotes approach, such as '°', the ° character has to first be in the source-code alphabet, which it probably isn't. You get around that by escaping it explicitly using the backslash and the character code. But that brings up the other issue in that escaping the character won't help if the character isn't in the execution character set or, probably more to the point, if the O/S's console font doesn't happen to include that symbol mapped to whatever code you are using for that symbol.Hi All,
Does anyone here knows how to display the 'degree' symbol in a string (C, C#, Java,...)?
e.g. To display 22 degree celsuis, I want to display it this way: 22 0C (Note the symbol is not displayed properly here)
Many Thanks
Eric
"Probably isn't" means it just may be. I guess millions of MPLab users aren't counted in the "probably."Not in any portable way. You have a couple of issue -- first is representing it to the compiler. To use the single-quotes approach, such as '°', the ° character has to first be in the source-code alphabet, which it probably isn't. You get around that by escaping it explicitly using the backslash and the character code. But that brings up the other issue in that escaping the character won't help if the character isn't in the execution character set or, probably more to the point, if the O/S's console font doesn't happen to include that symbol mapped to whatever code you are using for that symbol.
So in C you a pretty well screwed (at least doing it portably).
Since Java's native character set is Unicode (well, UTF-16), you almost certain can do it there -- I've just never done it so I don't know the ins and outs.
depending on display use printf(" temperature = %2.2f%dC", temp,223); // the 223 does the trick.Hi All,
Does anyone here knows how to display the 'degree' symbol in a string (C, C#, Java,...)?
e.g. To display 22 degree celsuis, I want to display it this way: 22 0C (Note the symbol is not displayed properly here)
Many Thanks
Eric
Yes, "probably isn't" does not preclude "it just might be". I'm talking about portability. If you want to encourage writing code that "might work", go right ahead."Probably isn't" means it just may be. I guess millions of MPLab users aren't counted in the "probably."
View attachment 116417
Program on right. Disassembly on left. Compiler MPLab.
John
So anytime a person prints out a decimal value that happens to be 223 they get a degree symbol?depending on display use printf(" temperature = %2.2f%dC", temp,223); // the 223 does the trick.
This works for sure with a matrix type display (HD 44780 most common)
Picbuster
It is not a matter of wanting to write non-portable code, it is a question of knowing the limitations of your compiler. If your compiler can only handle one radix, find a better compiler.Yes, "probably isn't" does not preclude "it just might be". I'm talking about portability. If you want to encourage writing code that "might work", go right ahead.
You are showing examples from assembly -- there IS no compiler, there is an assembler. Assemblers are notoriously nonportable -- it is rather difficult to write code of any complexity that will assemble and run on another assembler precisely because of the plethora of assembler-specific directives and pseudoinstructions and macro constructs and the list goes on that end up being used.It is not a matter of wanting to write non-portable code, it is a question of knowing the limitations of your compiler. If your compiler can only handle one radix, find a better compiler.
Wrong. The Assembler is a type of compiler. Please stop your obnoxious quibbling about words.WBahn said:You are showing examples from assembly -- there IS no compiler, there is an assembler.
No, it prints char(223) followed by a C when using the display as stated.So anytime a person prints out a decimal value that happens to be 223 they get a degree symbol?
I could see this working on "some" displays if a "%c" format specifier were used. But you would need to be sure that your users only ran your program on platforms that used those displays.
Unless your code is tightly bundled with the hardware -- which embedded code frequently is -- using "tricks" that are non-portable is usually a band aid that results in much more serious wounds to the patient when finally ripped off.
Look at the code carefully:No, it prints char(223) followed by a C when using the display as stated.
This will take two positions at your display. if however you want one character with the complete degree sign you have to build the character matrix.
Picbuster
by Jake Hertz
by Jake Hertz
by Jake Hertz
by Jake Hertz