Thread: char to bits representation

  1. #1
    Registered User
    Join Date
    Mar 2010

    char to bits representation

    Hi All
    Sorry for basic question but i am new to this problem. I search alot but could not succeed.

    I have 3x3 char array

    when i store them in an image using libtiff library on Linux OS,left most 1 appears on 8th position and second 1 appears on 16th position.

    I need them on first 2 positions as they are instead they are on 8th and 16th.

    How can i convert the above array to bits from chars so that it appears as it is, when i store in image.

    Thanks for help

  2. #2
    Registered User
    Join Date
    Mar 2007
    that's because a character, or unsigned character is represented by 8 bits. I think what you're after is 11000000 (binary) = 192 (decimal).

    What you have is 1,1,0 (decimal) = 00000001, 00000001, 00000000 (binary)

    EDIT: you could always bit shift the value 1 into a character/unsigned character. That would be another way of achieving 11000000.
    Last edited by scwizzo; 03-15-2010 at 06:28 PM.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    Have a look at the bit masking on the internet, it will show you on how to set and unset bits in a given btye.

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help :(
    By ramenen in forum C++ Programming
    Replies: 1
    Last Post: 02-17-2010, 04:31 PM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM