Keep a number as a byte?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 9
Reputation: Petrock6 is an unknown quantity at this point 
Solved Threads: 1
Petrock6 Petrock6 is offline Offline
Newbie Poster

Keep a number as a byte?

 
0
  #1
May 9th, 2009
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..
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,873
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 56
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: Keep a number as a byte?

 
0
  #2
May 9th, 2009
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.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 9
Reputation: Petrock6 is an unknown quantity at this point 
Solved Threads: 1
Petrock6 Petrock6 is offline Offline
Newbie Poster

Re: Keep a number as a byte?

 
0
  #3
May 10th, 2009
That's going to be a pain in the rear end -.-..
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 35
Reputation: NeoKyrgyz is an unknown quantity at this point 
Solved Threads: 1
NeoKyrgyz NeoKyrgyz is offline Offline
Light Poster

Re: Keep a number as a byte?

 
0
  #4
May 10th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC