943,616 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 523
  • C RSS
May 9th, 2009
0

Keep a number as a byte?

Expand Post »
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..
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Petrock6 is offline Offline
9 posts
since Mar 2008
May 9th, 2009
0

Re: Keep a number as a byte?

No. You'll have to write a cyclic shift macros or function. ie, something like
[code]#define cyclicShiftRight(val,shiftBy) ...code here...
  1. #define cyclicShiftLeft(val,shiftBy) ...code here...
  2. //...
  3. char num = 0x80; //1000-0000
  4. cyclicShiftRight/Left(num,3); //0000-0100
Last edited by twomers; May 9th, 2009 at 5:35 pm.
Reputation Points: 453
Solved Threads: 57
Posting Virtuoso
twomers is offline Offline
1,873 posts
since May 2007
May 10th, 2009
0

Re: Keep a number as a byte?

That's going to be a pain in the rear end -.-..
Thanks.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Petrock6 is offline Offline
9 posts
since Mar 2008
May 10th, 2009
0

Re: Keep a number as a byte?

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.
Reputation Points: 48
Solved Threads: 1
Light Poster
NeoKyrgyz is offline Offline
38 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: A little help with times and structures.
Next Thread in C Forum Timeline: create output files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC