Can this be done!

This is a discussion on Can this be done! within the Tech Board forums, part of the Community Boards category; Away from a compiler right now but I was thinking about the following code. The overall result will be to ...

  1. #1
    Registered User whistlenm1's Avatar
    Join Date
    Jan 2002
    Posts
    124

    Can this be done!

    Away from a compiler right now but I was thinking about the following code. The overall result will be to print the bit reprsentation of input.

    Thx

    [code]

    struct n_bits {
    unsigned int a:1;
    unsigned int b:1;
    unsigned int ...
    unsigned int p:1;
    }nbits;

    nbits = getchar();
    Man's mind once streched by a new idea, never regains its original dimensions
    - Oliver Wendell Holmes

    In other words, if you teach your cat to bark (output) and eat dog food (input) that doesn't make him a dog. It would have to chase cars, chew bones, and have puppies before I'd call it Rover ;-)
    - WaltP

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Not like that it can't - you would have to make the struct part of a union, with the other member of the union being an int.

    Besides, you're assuming a specific number of bits in a char/int/whatever

    It's much better to use a loop and CHAR_BIT from limits.h
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21