|
Ew, but yeah it may come to that. There's still gotta be a better way.
|
|
|
|
|
It seems that the word "octal" doesn't appear anywhere in the C# spec.
|
|
|
|
|
there are no "binary" or "hex" leywords either, but that doesn't stop us from using whatever we want as a number base.
|
|
|
|
|
As a matter of fact, I use beer as number base.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That won't cut it. Nobody would trust you dealing with beer-based numbers.
The way I know you, you would soon prove infinity does not exist.
|
|
|
|
|
Actually, I'm trying to reach infinity, but......... hic! ........... another one, plz plz!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Absolutely, great for bubble sorts without the expense that champagne incurs or the sugary-sweetness of cola.
|
|
|
|
|
No, but the words appear in the spec, as in:
binary-operator-declarator:
type operator overloadable-binary-operator ( type identifier , type identifier )
decimal-integer-literal:
decimal-digits integer-type-suffixopt
hexadecimal-integer-literal:
0x hex-digits integer-type-suffixopt
0X hex-digits integer-type-suffixopt
Not so for octal.
|
|
|
|
|
Actually, binary operators is a misnomer IMO; it really are bit-level operators meaning all the bits have independent meaning and behavior, there is no link to base 2 there.
I would not mind C# supporting binary and octal literals, hence also a convention to indicate those bases; and support for it in TryParse and ToString.
However I would very rarely use it; octal is thing of the past; some instruction sets got described in octal (e.g. PDP8 and PDP11), which looked OK at the time mainly because they had 8 registers so it was a signle digit that chose the register).
Binary notation tends to lack compactness; with a comma every 4 bits, an Int32 would take 39 characters.
|
|
|
|
|
Luc Pattyn wrote: binary operators
... operate on two operands. You know that.
Luc Pattyn wrote: supporting binary and octal literals
The C way of indicating octal literals is problematic. C# leaves it out, but that means that code copied from C will be broken with no alert.
I expect 0o10 would be better, with a warning if someone uses a capital O rather than a lowercase o , as with the l to indicate long.
Luc Pattyn wrote: octal is thing of the past
Yes, the only time I need octal is for OpenVMS UICs, and I still do see why they have to be done in octal.
Luc Pattyn wrote: Binary notation tends to lack compactness
Yeah, gimme Base-64 any day!
|
|
|
|
|
PIEBALDconsult wrote: binary operators
... operate on two operands. You know that.
Yeah, I used to known that (seems like the flu is not really helping me);
"binary operators" too is unrelated to base 2.
and bit-wise operators it the right term for some of the (mostly binary) operators
|
|
|
|
|
C# does not have octal literals(unfortunately). But we do have it in VB. So you have two ways:
1. Create a VB dll and refer it C#.
2. Get the data in string and write your own method to convert it to Octal.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
how bout:
public int Oct(int dec)
{
return ((dec / 8) * 10) + (dec % 8);
}
then
int octal = Oct(8);//should result in 10
|
|
|
|
|
The reason:
- We are dealing with number representaion in a given base, hence the function should return a string, not an integer.
- What if the input is
64 instead of 8 ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: should return a string
I disagree. Given a binary representation of 10-base10 [00001010], I want to get a binary representation of 10-base8 [00001000].
I'd rather not have to convert to string and back to do that, but I see no other way currently. And it may prove to be more efficient that way anyway.
Edit:
Or more clearly; in C, the statement int x = 010 ; results in a variable that contains the value eight, but in C# the result is the value ten.
It is desirable, in some cases, for int x = Oct ( 010 ) ; (or some such syntax) in C# to produce the desired value of eight, hopefully at compile-time as is the case in C (and apparently in VB.net).
modified on Friday, January 23, 2009 3:52 PM
|
|
|
|
|
You are talking about literals [^] (and you would like octal ones).
I still consider his proposed function conceptually (and technically) wrong.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: You are talking about literals
Ah, you're catching on.
CPallini wrote: conceptually (and technically) wrong
Oh, absolutely, but
public static int
Oct
(
int Value
)
{
return ( System.Convert.ToInt32 ( Value.ToString() , 8 ) ) ;
}
just seems dirty (but not as dirty as resorting to VB).
|
|
|
|
|
musefan wrote: public int Oct(int dec)
{
return ((dec / 8) * 10) + (dec % 8);
}
That does not make sense whatsoever. An integer number has one value, and it does not know anything about bases. Five is five, ten is ten.
It is only when you want to perform (mostly human) I/O that you need conversion to/from a string, and that is where the notion of base, and some conventions about how to indicate such base, come into play.
A nasty result of your way is arithmetic starts to fail pretty soon:
int decimal5=5;
int octal5=Oct(decimal5);
int decimal12=12;
int octal12=Oct(decimal12);
int octalSum=octal5+octal12;
Console.WriteLine(octalSum);
The bormal thing to do to get it work correctly all the time is using integers without caring about base, except for when you perform input/output. Hence:
int five=ReadAnOctalNumberFromConsole();
int twelve=12;
int sum=five+twelve;
WriteToConsoleUsingOctal(sum);
So you would have to come up with two methods.
There is one laborious alternative, very bad for performance: you could implement all arithmetic yourself, and always operate on strings, as in:
string five="5";
string twelve="12";
string sum=OctalStringArithmetic.Add(five, twelve);
Console.WriteLine(sum);
[ADDED] Addition in strings is easy, multiplication is harder; division, square root, and
all transcendentals are rather hard to do.[/ADDED]
modified on Friday, January 23, 2009 8:11 AM
modified on Friday, June 10, 2011 12:06 PM
|
|
|
|
|
Will that only work with one- and two-digit octal values?
P.S. And I would expect that to work as Oct ( 10 ) yields 8
modified on Friday, January 23, 2009 12:29 PM
|
|
|
|
|
OK forget my attemp, it does not work after 63(DEC)
But to say it has to be a string is wrong, it all depends what you want to do with the result
|
|
|
|
|
There is no octal (or binary) literal in C#. I rolled my own in this article[^].
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hi friends
how to create dll(dynamic link library) for user developed projects
the quieter u become more u hear
|
|
|
|
|
"user developed projects"? What?
csc /target:library somefile.cs
|
|
|
|
|
hey guys
i want to ask same thing also... i did it by using command prompt
but how i can make it by using visual studio..i thought i can create a dll by building solution but i have nothing on the root file of the project.. but when i did like that
csc /target:library somefile.cs
i had it..so how i will do it by using visual studio ?
|
|
|
|
|
erdinc27 wrote: nothing on the root
VS creates bin\debug and bin\release directories and hides it there.
|
|
|
|