Thread for the C/C++ Beginners and Programmers!

Guys can u help me!I wanted to know the formula of converting Octal to Hexadecimal number and also the Hexadecimal to Octal number!I know the other 10 formulas but nnot these two.
 
ritwik said:
BTW, sid sorry but I am somewhat out of sorts with TCP, but who's been doing the coding for that game ? And how many people are there ?

EDIT: Still waiting for the correct response to my query. Waiting for austin, Siddharth and others to give it a go. Rep bonus (and a big one :), if you get my drift) for the correct answer.

The coding and major other work is being done by Paul Snell(member name as legend_master).There are many other's helping him in every department(most notably jk16_4,Hariz and Holmie and Manee).

gaurav_indian said:
Guys can u help me!I wanted to know the formula of converting Octal to Hexadecimal number and also the Hexadecimal to Octal number!I know the other 10 formulas but nnot these two.

The easiest way to implement this in programming would probably be by using the format specifiers(%x,and %o)

But to convert them,I think they need to be converted to binary first and then to octal(although there might be other short cut methods)
 
Last edited:
FINALLY !

Congrats, Sid. Well done.

There were just a few very minor issues with your program, which I've corrected and I repost it as follows:

code said:
#include<iostream.h>
#include<conio.h>
int main()
{
long int x;
long int *a=0;
cout<<"Enter the size";
cin>>x;
a=new long int[x];
for(int i=0;i<x;i++)
{
cout<<"Enter %d number"<<i+1<<" ";
cin>>a;
}
for(i=0;i<x;i++)
{
cout<<"The array elements are\n"<<a;
}
delete[] a;
return(0);
}

Notes
1. In the line: cout<<"Enter %d number"<<i+1<<" ";
I've replaced the x with i, you just missed that out accidently I guess.
2. a=new long int[x];
you failed to mention "long".

Excellent work, though. A 50 point rep bonus on its way ....... not that you need it though.
 
sid_19840 said:
The easiest way to implement this in programming would probably be by using the format specifiers(%x,and %o)

But to convert them,I think they need to be converted to decimal first and then to octal(although there might be other short cut methods)
But I wanted to know these two formulas.As I have said earlier I know the other 10 number conversion formulas but not these two.I know it can be converted if we change the format specifiers but that's not good for a better program.
 
ritwik said:
FINALLY !

Congrats, Sid. Well done.

There were just a few very minor issues with your program, which I've corrected and I repost it as follows:


Notes
1. In the line: cout<<"Enter %d number"<<i+1<<" ";
I've replaced the x with i, you just missed that out accidently I guess.
2. a=new long int[x];
you failed to mention "long".

Excellent work, though. A 50 point rep bonus on its way ....... not that you need it though.

Cheers,more importantly,I learnt something.

ok here is one.(I think this can be done with both C and C++)

W.A.P which will delete itself on execution.
 
Guys can u help me!I wanted to know the formula of converting Octal to Hexadecimal number and also the Hexadecimal to Octal number!I know the other 10 formulas but nnot these two.

Don't know quite what you mean by "formula" but the easiest way IMO would be to convert your octal number to decimal by multiplying each place by powers of eight(remember the place value system ? this works the same way). Once you've got your decimal number, divide it repeatedly by 16 and store the remainders in an array, which you then read backwards to get the correct hexadecimal answer(While printing the answer, don't forget to replace 10 with A and so on).

I think there might be other, more direct ways to do it or maybe some C++ trick/function that accomplishes this, though.
 
gaurav_indian said:
But I wanted to know these two formulas.As I have said earlier I know the other 10 number conversion formulas but not these two.I know it can be converted if we change the format specifiers but that's not good for a better program.

Consider the number 52(in hex)

Converting to binary

8421 8421
0101 0010

Now group these into groups of 3.

421 421 421
001 010 010

which comes to 122 in octal.Similarly the opposite can be done.
 
W.A.P which will delete itself on execution.
I think in theory, you'll make a pointer point to where the program code is in memory and then deaollocate it or something ?

I'll try it out.
btw, does this involve pointer to pointers ?

And i think this ain't a very good question (although its hard) since this will be very specific to the system you're on. Since different platforms handle executables and memory in different manners.
 
It means that if I want to convert octal number to hexadecimal and vice versa then first I have to convert it to decimal number if that's the case I think I have found the answer.And ritwik I mean formulas bcoz there is a formula for every conversion like u said the place value system I know that very well.Thanx.
 
ritwik said:
I think in theory, you'll make a pointer point to where the program code is in memory and then deaollocate it or something ?

I'll try it out.

Im not sure about it as Ive never tried anything like that.

HINT:There is a function in the stdlib that might help.

gaurav_indian said:
It means that if I want to convert octal number to hexadecimal and vice versa then first I have to convert it to decimal number if that's the case I think I have found the answer.And ritwik I mean formulas bcoz there is a formula for every conversion like u said the place value system I know that very well.Thanx.

I have converted them to binary and not decimal,as its easier.
 
Consider the file name to be abc.cpp, then this code will work.

#include<stdio.h>
void main()
{
char name[]="abc.cpp";
remove (name);
}
 
Abhas said:
Consider the file name to be abc.cpp, then this code will work.

#include<stdio.h>
void main()
{
char name[]="abc.cpp";
remove (name);
}

Good work,try taking this one step further,assuming that we dont know the name of the file.

HINT:Command Line Arguments. ;)
 
Last edited:
I've figured it out using the pointer appraoch:





#include <stdlib.h>

#include <stdio.h>

#include<conio.h>

int main(int var1, char * * path) // path gets starting location

{ clrscr();

getch(); // press a key for program to end and auto delete exe file.

remove(path[0]);

return EXIT_SUCCESS; // for normal program termination.Value returned to main.

}

you don't need the name of the file.

EDIT: Ofcourse, you can ignore the last line in case you like to use void main.


#include<stdio.h>
void main()
{
char name[]="abc.cpp";
remove (name);
}
You're removing the .cpp file. it should be the .exe file, since when the program is executed, it is from the exe file and it has to delete itself.
good logic though. Just replace the .cpp with the .exe and I think you'll be ready to go !
 
ritwik said:
I've figured it out using the pointer appraoch:





#include <stdlib.h>

#include <stdio.h>

#include<conio.h>

int main(int var1, char * * path) // path gets starting location

{ clrscr();

getch(); // press a key for program to end and auto delete exe file.

remove(path[0]);

return EXIT_SUCCESS; // for normal program termination.Value returned to main.

}

you don't need the name of the file.

EDIT: Ofcourse, you can ignore the last line in case you like to use void main.
It looks like you are a champ in C and C++ that's why I started this thread so that I can get the solution of my problems here.Once i'll start revisioning C a lot of problems will occur and i'll give u those.
 

Users who are viewing this thread

Top