C/C++ shift function

Discussion in 'Software' started by ardebaran, Feb 4, 2005.

  1. ardebaran

    ardebaran Private E-2

    hello i want to do a kind of encripter, first i need to change a letter to the BIN code, and then use some shift function to change the order of the BIN code, for example if i have 01 change to 10, or 10 -> 01 to generate another letter in Binary code. please can anyone give me a suggestion?? thanks !!

    l.terrero@verizon.net.do
     
  2. Eklipz

    Eklipz Private E-2

    You don't need to convert anything to binary in order to shift it. Let's say you have a variable, x, with the value 9. In binary, this is 00001001. Now, if you wanted to shift all of the digits to the left by 1 position, all you would need to do is use the following command:

    x << 1;

    At the end of the shift, the value of x would now be 18, or 00010010. Now, in order to undo this, just shift it 1 position to the right. This can be done with the following command:

    x >> 1;

    Now the binary digits shift to the right, giving us 9 again, or 00001001.

    You can mess around with the number by which you shift. Each successive shift to the left essentially multiplies the number by 2, and each successive shift to the right essentially divides the number by 2. For example, if we used the following command:

    x << 3;

    Then x would be equal to 72, or 01001000. (9 * 2 * 2 * 2).

    Hopefully this is enough information to get you started on your encryption scheme.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds