Respected experts i am doing a project on the basis of c,
For this I need a guidelines.
After converting the ASCII value of the charecter that will be converted
to its binary format till this i did it.but now i want to set the specified bit in that binary format on the basis of this condition.
1)If any bit value which is ANDed to the perticular bit position in the binary format it should set so that
1 2^(bit-1) =2^0 if bit=1
2 2^(bit-2) =2^1
3 2^(bit-3) =2^2
4 2^(bit-4) =2^3
if(N&ch)=N WHERE N is a specific bit.
/*prg to find ascii of a charecter*/
# include<stdio.h >
#include<conio. h>
#include<iostre am.h>
#include<conio. h>
#include<math.h >
class Bits {
char ch ;
public :
Bits ( char c ) {
ch = c ;
}
void showBits() ;
void setBit ( int ) ;
void operator = ( char c ) {
ch = c;
}
} ;
void Bits::showBits( ) {
int i,c ;
cout << "\n\n " << ch << "\t" ;
for ( i = 128 ; i >= 1 ; i >>= 1 )
( (i&ch) == i ) ? ( cout << 1 ) : ( cout << 0 ) ;
}
void main()
{
Bits b ('A' ) ;
clrscr() ;
b.showBits() ;
b = 'a' ;
b.showBits() ;
}
o/p:
A=01000001
a=01100001
For this I need a guidelines.
After converting the ASCII value of the charecter that will be converted
to its binary format till this i did it.but now i want to set the specified bit in that binary format on the basis of this condition.
1)If any bit value which is ANDed to the perticular bit position in the binary format it should set so that
1 2^(bit-1) =2^0 if bit=1
2 2^(bit-2) =2^1
3 2^(bit-3) =2^2
4 2^(bit-4) =2^3
if(N&ch)=N WHERE N is a specific bit.
/*prg to find ascii of a charecter*/
# include<stdio.h >
#include<conio. h>
#include<iostre am.h>
#include<conio. h>
#include<math.h >
class Bits {
char ch ;
public :
Bits ( char c ) {
ch = c ;
}
void showBits() ;
void setBit ( int ) ;
void operator = ( char c ) {
ch = c;
}
} ;
void Bits::showBits( ) {
int i,c ;
cout << "\n\n " << ch << "\t" ;
for ( i = 128 ; i >= 1 ; i >>= 1 )
( (i&ch) == i ) ? ( cout << 1 ) : ( cout << 0 ) ;
}
void main()
{
Bits b ('A' ) ;
clrscr() ;
b.showBits() ;
b = 'a' ;
b.showBits() ;
}
o/p:
A=01000001
a=01100001