bit conversions

This is a discussion on bit conversions within the C Programming forums, part of the General Programming Boards category; does anybody have or know of a bit conversion table or program, or even a website, one that uses the ...

  1. #1
    Registered User wazilian's Avatar
    Join Date
    Oct 2001
    Posts
    26

    Question bit conversions

    does anybody have or know of a bit conversion table or program, or even a website, one that uses the bitwise operators.

    for example, something that would give you the bit pattern to change:

    1000 0000

    to

    10010100

    using '|' '&' bitwise operators

    so like if you know what pattern you start with and you know what pattern you need, a table or program gives you the 2nd bit pattern. need this more for haste instead of trying to calculate the needed bit pattern on my own. thanx in advance.
    wazilian
    King of Wazil

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Sounds like homework to me.

    1) Read a string of 0s and 1s
    2) Read an operator to use.
    3) Read a second "binary" string.
    4) Apply the "operator".
    5) Print the results.

    Quzah.

  3. #3
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284

    Re: bit conversions

    Originally posted by wazilian
    does anybody have or know of a bit conversion table or program, or even a website, one that uses the bitwise operators.

    for example, something that would give you the bit pattern to change:

    1000 0000

    to

    10010100

    using '|' '&' bitwise operators

    so like if you know what pattern you start with and you know what pattern you need, a table or program gives you the 2nd bit pattern. need this more for haste instead of trying to calculate the needed bit pattern on my own. thanx in advance.
    change:

    a=1000 0000

    to

    b=10010100

    isnt a | b= b in this case )

  4. #4
    Registered User Null Shinji's Avatar
    Join Date
    Oct 2001
    Posts
    80
    you wanna change between binary to decimal???
    well look

    you can read the string and then make a for like this

    for(i=0;i<strlen(string);i++){
    if (string[i]=='1') a|=(1<<strlen-1-i);
    }


    a is an int....
    a is the decimal value of the binary number you saved on the string
    Null Shinji The Sorcerer is here
    Evangelion Quotes:
    "If youre gonna do it, dont waste time. Otherwise, leave", Gendo
    "Release the final safety lock, Evangelion Unit One, Lift Off!!", Misato
    "Syncrograph has reversed, pulses are flowing back!!!", Maya
    streamload id= nullshinji icq= 12944337; E-M@IL= nullshinji@gmx.net; aim= mayeba
    msn= mayeba86@hotmail.com

  5. #5
    Registered User Null Shinji's Avatar
    Join Date
    Oct 2001
    Posts
    80
    Originally posted by Null Shinji
    you wanna change between binary to decimal???
    well look

    you can read the string and then make a for like this

    for(i=0;i<strlen(string);i++){
    if (string[i]=='1') a|=(1<<strlen-1-i);
    }


    a is an int....
    a is the decimal value of the binary number you saved on the string
    ahh i forgot from dec to binary..


    s[32]=0;
    for(int k=0;k<32;k++){
    if(c&(1<<k)) s[31-k]='1';
    else s[31-k]='0';
    }
    int l=0;
    while(s[l]=='0'){
    l++;
    }
    memmove(s,s+l,33-l);
    printf("%s",s);

    then s is the string where you keep the binary form of the decimal you saved on c
    Null Shinji The Sorcerer is here
    Evangelion Quotes:
    "If youre gonna do it, dont waste time. Otherwise, leave", Gendo
    "Release the final safety lock, Evangelion Unit One, Lift Off!!", Misato
    "Syncrograph has reversed, pulses are flowing back!!!", Maya
    streamload id= nullshinji icq= 12944337; E-M@IL= nullshinji@gmx.net; aim= mayeba
    msn= mayeba86@hotmail.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-10-2005, 09:53 AM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  4. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 07:02 PM
  5. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 02:17 PM

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