954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Keep a number as a byte?

Hello.
I'm developing a encryption program. I'm testing with encryption right now.
I use bitwise operators and also bitwise shifts. [OR [|], XOR[^], AND[&], NOT[~], right[>>],left[<<]]

To add even more security, I went ahead and added bitwise shifts.
Whenever I shift the numbers, they go over 256 [max int in a byte].
Is there any way I can declare the integer so that it doesn't go above 256, and if it does it just overlaps?

I'm sorry I can't explain it well, I know C very little..

Petrock6
Newbie Poster
10 posts since Mar 2008
Reputation Points: 10
Solved Threads: 1
 

No. You'll have to write a cyclic shift macros or function. ie, something like
[code]#define cyclicShiftRight(val,shiftBy) ...code here...

#define cyclicShiftLeft(val,shiftBy) ...code here...
//...
char num = 0x80; //1000-0000
cyclicShiftRight/Left(num,3); //0000-0100
twomers
Posting Virtuoso
1,877 posts since May 2007
Reputation Points: 453
Solved Threads: 57
 

That's going to be a pain in the rear end -.-..
Thanks.

Petrock6
Newbie Poster
10 posts since Mar 2008
Reputation Points: 10
Solved Threads: 1
 

You can store it in a char (8 bit) variable.
Even if "char" gives impression of "character" variable actually it's just a integer of 8 bits.

This should solve you problem if I got it correctly. Otherwise please clarify your problem.

NeoKyrgyz
Light Poster
38 posts since Jan 2009
Reputation Points: 48
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You