ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have written a simple program in c++ to convert a byte to binary number but i do not understand what the complier is try to tell me. the program and error are below.if any one can understand them please mail me. Cheers!!
====================
C++ Program (cnvt.cc)
====================
#include <iostream>
void binary_op(char byte);
int main()
{
char byte=55;
binary_op(byte);
return 0;
}
here is the error when i have tried to compiled the program
the commad i used and the errors are showen below
suman@linux:~> gcc cnvt.cc
======
errors
======
/tmp/cc1RdLHm.o(.text+0xa0): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/cc1RdLHm.o(.text+0xcf): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/cc1RdLHm.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
to make it c replace '#include <iostream>' with '#include <stdio.h>' and rename to cnvt.c
to make it c++ replace '#include <iostream>' with '#include <cstdio>' add the line 'using namespace std;' after the #include and compile with g++ not gcc
well all (signed integer)numbers are stored in two's complement binary notation so any of int, char, long, etc store the numbers in binary. if your actual question is - is there a function to convert a number to a base2(binary) string then there is, its called itoa but unfortunatly its not ansi c, i dont know if gcc supports it or not. its better to write your own version of itoa as its not very hard to do.
The other way is to change your number into string (using itoa(), which is an ANSI C function, or sprintf()) and then strtoul() or strtol().
But that's too dirty. The best way is to use bitwise operators.
hi mohsen
i do not think those function will work in GCC. but i will try them out. i think the best option will be to a customised function than relying on the inbuild ones.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.