Thread: assign bits

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    30

    assign bits

    anyone know how to assign bit in C

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    424
    Yes.

  3. #3
    Registered User
    Join Date
    Jan 2021
    Posts
    30
    Quote Originally Posted by hamster_nz View Post
    Yes.
    could you tell me?

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    424
    What's the question? What do you want to do.

  5. #5
    Registered User
    Join Date
    Jan 2021
    Posts
    30
    Quote Originally Posted by hamster_nz View Post
    What's the question? What do you want to do.
    My question is: how do I assign a bit on C programming

  6. #6
    Registered User
    Join Date
    Sep 2020
    Posts
    424
    Usual use binary AND or OR operators.

    C does have bit fields, but they are not used much.

  7. #7
    Registered User
    Join Date
    Jan 2021
    Posts
    30
    Code:
    {
       unsignedint widthValidated :1;
       unsignedint heightValidated :1;
    } status;


    I researched this is how bits are assigned, but it only works for 1 and not 0

    how do I assign 0?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    So what do you see when you do

    status.widthValidated = 0;
    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.

  9. #9
    Registered User
    Join Date
    Jan 2021
    Posts
    30
    Quote Originally Posted by Salem View Post
    So what do you see when you do

    status.widthValidated = 0;
    ahh nice, does that work with 1 too?
    Last edited by oods1; 01-12-2021 at 11:21 AM.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    You asked?

    You have a compiler sitting in front of you, and it was a 1 character change to change 0 to 1 and find out.
    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.

  11. #11
    Registered User
    Join Date
    Jan 2021
    Posts
    30
    Quote Originally Posted by Salem View Post
    You asked?

    You have a compiler sitting in front of you, and it was a 1 character change to change 0 to 1 and find out.
    ye i get it, was obvious lol

    Also,

    for example, int data type is 8 bits, is there a data type which is 1 bit?
    Last edited by oods1; 01-12-2021 at 11:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing particular bits and detecting toggled bits
    By Nordomus in forum C++ Programming
    Replies: 11
    Last Post: 04-13-2018, 12:07 PM
  2. Assign index value to bits in cyclic order
    By patneel in forum C Programming
    Replies: 5
    Last Post: 03-13-2012, 05:51 AM
  3. Extracting certain bits from sequence of bits
    By lucaspewkas in forum C Programming
    Replies: 5
    Last Post: 10-06-2007, 12:22 AM
  4. New idea on conveting byte to bits/bits to byte
    By megablue in forum C Programming
    Replies: 10
    Last Post: 10-26-2003, 01:16 AM
  5. copy some bits into a 8 bits binary number
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 05-29-2002, 10:54 AM

Tags for this Thread