Thread: showbits

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    3

    showbits

    Hi all

    in windows programming there is a
    function named "showbits" which displays
    a particular value into its binary form...
    Is there as such function available for linux also?

    plz comment


    thanks & regards
    Sanjeev

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    No, but rolling your own is not too difficult.
    http://www.daniweb.com/code/snippet148.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Not that I know of. However, it's not too difficult to come up with a string representation of the bits using some simple bitwise operations. If there is no standard alternative, I'd suggest writing a function for it.

    EDIT: Sorry, wrote this a while ago, just forgot to submit it. :/
    Sent from my iPadŽ

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you search this board for "number binary representation" or something similar, you'll find lots of hits. It comes up every once in a while.

    EDIT: Sorry, wrote this a while ago, just forgot to submit it. :/
    Multiple tabs/windows, eh?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    char *table[] = {
       "0000000000000000",
       "0000000000000001",
       "0000000000000010",
       "0000000000000011",
        // etc etc
    };
    printf("%s", table[value]);
    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.

  6. #6
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    When I was doing bit manip/reading in Java... I converted each byte to a array of bools... I made a class to handle all the stuff for me but essentually, I had something to convert an array of bools to any type and I had a to string funtion that I used for printing it... it is relatively easy to just shift and check to see if it ANDs with 1 to make the array. I am sure it would be pretty easy to implement it in other languages... (I think I have a Perl version laying around too...)

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    3
    thanks Brian....



    Quote Originally Posted by sanjeev_ddas
    Hi all

    in windows programming there is a
    function named "showbits" which displays
    a particular value into its binary form...
    Is there as such function available for linux also?

    plz comment


    thanks & regards
    Sanjeev

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. showbits()???
    By kashifk in forum C Programming
    Replies: 5
    Last Post: 06-01-2003, 05:24 AM