473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how do i store byte array of16 elements as one no.

i have a byte array having 16 elements i.e 128 bits.. i want to do bit manipulations on this 128 bit byte array
how can i store this 128 bit as one no.so i can do bit manipulations
Mar 23 '10 #1
5 2594
jkmyoung
2,057 Expert 2GB
Are you talking about an byte array have size 16, eg byte[16], or one massive number with 128 bits?

If the latter, then you can write your own class or use a BitSet

What bit manipulations are you talking about specifically? &, |, ~, >>, >>>, <<, HighestSetBit, LowestSetBit, # of set bits, etc...
Mar 23 '10 #2
i have a byte array say byte_array[16]
i want to perform a circular shift on the byte array
Mar 24 '10 #3
jkmyoung
2,057 Expert 2GB
You'll have to create your own class. Do you shift frequently, or only occasionally? Are you getting the elements by the byte?

If you shift a lot, one possibility is to keep an integer representing the shift, and adjust the result bytes whenever you access it.
Mar 24 '10 #4
i am implementing idea encryption algo
i have to perform a left circular shift by 25 on the byte array i.e byte_array[16] which is nothin but my key..
then take some elements from the byte array to form the subkeys and then again perform circular left shift by 25 on the entire byte array to generate subkeys for the next rounds.. i know how to do a circular shift
but the problem is byte_array[16] has altogether 128 bits.. nd i dont know where to store this 128 bits to perform a circular shift operation..
Mar 25 '10 #5
jkmyoung
2,057 Expert 2GB
Assuming byte_array[0] is the leftmost set of bits.
One problem you will encounter is that java does not have unsigned bytes. Thus we are using a ushort[] array instead in this example:

Expand|Select|Wrap|Line Numbers
  1. ushort[] shiftLeft(ushort [] byte_array, int shift){
  2.   int length = byte_array.length;
  3.   short index;
  4.  
  5.   shift %= length * 16;
  6.   short wholeByteShift = shift/16;
  7.   short partByteShift = shift%16;
  8.  
  9.   ushort[] retVal = new ushort [length];
  10.   for (int i = 0; i < length; i++){    
  11.     retVal[i] = byte_array[(i+wholeByteShift)%length] << partByteShift;
  12.     retVal[i] |= byte_array[(i+1+wholeByteShift)%length] >> partByteShift;
  13.   }
  14.   return retVal;
  15. }
Mar 25 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
3
by: jacob nikom | last post by:
Hi, I would like to be able to store numerical array in MySQL. I am really looking for the solution to store it in the one field only. For example, I have a matrix, which I want to store in...
2
by: TDH | last post by:
Hi, I need to do a raw copy of a byte array to an Int16 array. For e.g., I have an byte array which has length 100, and I need to copy this to an Int16 array that has length 50. So 2 elements...
3
by: Steve Mauldin | last post by:
I came across an example in the MSDN documentation using RC2 encryption(the link to the article is at the end of this message). When I tried it I had a problem with getting back the same length...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
32
by: Guoqi Zheng | last post by:
I am really do not know so much about byte/bit, etc. Question, if I defined a byte(), how can I add a single byte to it? what I want is that I have an array of bytes, I loop that array, look at...
5
by: paul | last post by:
Hi all, Could some kind soul peruse the following code and see if there is anything wrong with it? Its producing output, but its only occupying the first third of the output array; to give an...
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.