|
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.
|
|
|
|
|
but there is no release file only debug file i have here...where it creats the release file ?
|
|
|
|
|
First, perform a release build...
|
|
|
|
|
Double click on project Properties and set 'Output Type' to 'Class Library'
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
hi,
i think you are asking about building & releasing your code (so called user developed projects. right?)
if you are doing so in web application, then obviously this is not the place to ask.
however, you can do:-
1. right click on the project
2. chose Publish
3. browse the location where to publish the project (even FTP, HTTP)
4. check/uncheck the options if required so. (use progressive build)
5. Publish it
you are done. Ask any clarifications
Ashish Sehajpal
|
|
|
|
|
thanks
the quieter u become more u hear
|
|
|
|
|
Is it possible to get the program's own filename on runtime?(exe file)
|
|
|
|
|
Yes, of course.
OK, here's what I use:
System.Windows.Forms.Application.ExecutablePath
and sometimes I pass that through
System.IO.Path.GetFileNameWithoutExtension()
modified on Thursday, January 22, 2009 10:40 PM
|
|
|
|
|
PIEBALDconsult wrote: Yes, of course.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
Get the current process using Process.GetCurrentProcess()
Then use the ProcessName or MainModule property.
«_Superman_»
|
|
|
|
|
I don't think that'll work reliably.
|
|
|
|
|
You mean, we would not always get the filename ?
«_Superman_»
|
|
|
|
|
Is there a guarantee that the process name is the filename?
On the other hand I just tried it and it seems to be reliable.
At least it knows if I change the file name.
I may need to look into it further.
|
|
|
|