Write a macro to set the nth bit ?
Click for Solution

  • Warning: Illegal string offset 'name' in /home/prepdo6/gpl4you/discussquessub.php on line 681
    A #define set(x) pow(2,x) void main() { int num,x; num=num|set(x); }

    CpjJwWHV   your program will then become.......................
    #define set(x) pow(2,x)
    void main()
    {
    int num,x;
    num=num|(int)set(x);
    }
    14 years ago
    CpjJwWHV   your program will then become.......................
    #define set(x) pow(2,x)
    void main()
    {
    int num,x;
    num=num|(int)set(x);
    }
    14 years ago
    CpjJwWHV   yes.i agree wid subhash.
    14 years ago
    CpjJwWHV   yes u should write num=num|(int)set(x);
    14 years ago
    CpjJwWHV   isnt it should be ,, pow(2,(x-1))
    becoz setting nth bit, let 4th bit means 2^3,
    as bit starts with 2^0 , 2^1, 2^2, and 4th bit 2^3
    14 years ago

    Smiley

[Insert Code]