|
Luc Pattyn wrote: Yes, that is correct.
Thanks I got one right
Luc Pattyn wrote: If you start off with a long, an int, a short then it would be a pitty to first
create a byte array.
Why would it be bad to create a byte array?
Luc Pattyn wrote: you could swap bytes in situ:
I think I might just do that.
Thanks for you input.
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
jason_lakewhitney wrote: Why would it be bad to create a byte array?
It is not bad, but why create and work with an object if there exists a simple
solution without such object.
Hence, if you start off with a byte array, operate on it; if you start off with
a long/int/short, operate on it. Example:
ushort val=0x1234;
val=EndianChanged(val);
...
public ushort EndianChanged(ushort val) {
return val=(val>>8) | (val<<8);
}
As you can guess, this method is much cheaper than the byte-array based solution,
it is less code and no new objects.
Of course, if you need this endian changing only a couple of times, it does not
matter how you do it. If you are going to read an entire binary program file,
maybe several MB in size, it may well matter.
r
|
|
|
|
|
Okay I did a test to understand whats going on and verify the correct method to use
and this is what I came up with:
234
Array Flip: -369098752
Int Shift: 59904
IPAddress: -369098752
The reason why I wanted to write my own method instead of using IPAddress is so that I
could understand whats going on and also I don't want to have to referance it.
I am not trying to be a pain I just want to know which is right and I'll use it.
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
Hi,
I am not sure I understand your last message completely, here are some thoughts:
- my val=(val>>8) | (val<<8) code is probably not completely accurate, I guess
it will need an overall cast to get rid of the intermediate data type (without
it, the compiler would complain; and when changing the return type, the value
would be wrong, since the left shift must loose its top byte).
- I dont see how it would ever turn (0,0,0,234) into (0,234,0,0).
- for testing purposes it is best to use a hex number that fills the variable,
so for an ushort I would use 0x1234, for a uint 0x12345678; this gives a maximum
of information while debugging
- yes you can use IPAddress.HostToNetworkOrder, but that is not what I would do
since the method's name does not reflect the intention. You could hide it
inside your own ChangeEndianness() method tho.
|
|
|
|
|
Okay, its a new day lets look at this again.
using hex 0x12345678 = 305419896 that
gives us an array of bytes:
Byte: 120
Byte: 86
Byte: 52
Byte: 18
(If I am thinking correctly)Switching this from little endian to big endian
we would need to basically reverse the order of the bytes:
Byte: 18
Byte: 52
Byte: 86
Byte: 120
which is hex 0x78563412 = 2018915346
val = (val >> 8) | (val << 8) gives us:
Byte: 86
Byte: 124
Byte: 86
Byte: 52
which is hex 0x34567C56 = 878083158
Using your -val = (val >> 8) | (val << 8)- we are shifting bits, but I didn't think that is what
the problem is. For assumption was that big and little endian determined which way the bytes were
laid out. For example: 0x12345678 has 4 bytes(32-bits)-bytes:Z=120,Y=86,X=52,W=18. Now this is in
little endian basically because this machine uses little endian. Or in other words the bytes are read right to left in a least to greatest manner. Say that big endian is the opposite, then big read left to right in a least to greatest manner also. Big endian byte arrangement to 0x12345678 would be: W=18, X=52, Y=86, Z=120.
I am questioning things not to be a pain, but to make sure I understand. It seems to me that your are trying to shift bits when what is need is the bytes' order to be reversed. Yes/No
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
Hi,
the example I gave was handling unsigned shorts, these hold two bytes, hence the
formula included just one OR operator.
For (unsigned) ints, you need to swap 4 bytes, hence 3 OR operators; plus some
masking to avoid bit aliasing.
You could also do it pseudo-recursively like so:
// Swaps all bytes of a uint
public static uint Swap(uint val) {
return (uint)( swapLowerTwoBytes(val)<<16 | swapLowerTwoBytes(val>>16) );
}
// Swaps a ushort (but accepts and returns it as a uint)
public static uint swapLowerTwoBytes(uint val) {
ushort sval=(ushort)val; // throw away top bytes
return (ushort) ( (sval<8) | (sval>8) );
}
Both methods look very similar, I added the (uint) cast for clarity although
it is not needed; both (ushort) casts are necessary to throw away irrelevant bytes.
For signed int, it is similar, but be careful the sign bit gets replicated when
shifting right; either use an explicit AND, or cast to unsigned first.
Hope this helps.
BTW: when I told you to use a recognizable hex test value, the basic idea
is to do all printout in hex too !
|
|
|
|
|
Thank you for the time you spent on this matter.
I think we've got it worked out.
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
You are welcome.
I hope you are sure you understand the problem and the solutions (with and
without byte array).
|
|
|
|
|
Never mind I got it:
return val = (val >> 24) |(val << 24);
Yep your right that is better.
Thanks for the time and help.
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
?????????
what is val's type ? what did you do to my code, now it is completely wrong.
[1]
ushort val=0x1234 ?
val>>24=0
val<<24=0
so it returns 0
[2]
uint val=0x12345678 ?
val>>24=0x00000012
val<<24=0x78000000
so it returns 0x78000012 ????
?????????
|
|
|
|
|
Well after some searching on the subject I got it figured out.
Here is what I am using to do the flipping it should handle any size:
static byte[] FlipBytes(byte[] bArray)
{
byte[] bNewArray = new byte[bArray.Length];
int j = 0;
for (int i = bArray.Length - 1; i >= 0; i--)
{
bNewArray[j] = bArray[i];
j++;
}
return bNewArray;
}
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
I am using Publish Feature of Microsoft Visual Studio 2005(Visual C#) , I can easily Publish and install the updates with one click, BUT the PROBLEM is that it downloads the updates under the Logged-on user profile as C:\Documents and Settings\salman\Local Settings\Apps\2.0\MZ4LCEX9.335\8Q3D2HW5.Q2O\manifests\....
Whereas, i want to specify a download location during publishing the project.
Please help me this is very very urgent.
thanks.
|
|
|
|
|
You posted the same question just a few minutes ago. Please delete the previous post.
__________________
Bob is my homeboy.
|
|
|
|
|
You can't specify install directory on client if you use ClickOnce... If that is absolutely necessary, well -> then you'll have to use some other deployment technology.
However, if you provide me with more info on what you're trying to achieve, I'm willing to give you more suggestions.
Enjoy!
|
|
|
|
|
Hi all,
Ive been using log4net as my logging framework of choice anybody who has used it will agree its really great ! (beats the microsoft logging block)
Now my question ?
I would like to add a SMS Appender feature that will send an sms to a mobile phone as an addtional logging feature, how do i go about adding appenders of my choice ?
Thanks !
|
|
|
|
|
|
|
I am using Publish Feature of Microsoft Visual Studio 2005(Visual C#) , I can easily Publish and install the updates with one click, BUT the PROBLEM is that it downloads the updates under the Logged-on user profile as C:\Documents and Settings\salman\Local Settings\Apps\2.0\MZ4LCEX9.335\8Q3D2HW5.Q2O\manifests\....
Whereas, i want to specify a download location during publishing the project.
Please help me this is very very urgent.
thanks.
|
|
|
|
|
Hello,
i'd like to remove the pointer of the datagridview, i don't know exactly the name of that.
look the picture:
http://img105.imageshack.us/my.php?image=pointerua1.jpg
thank you !!
|
|
|
|
|
Don't keep reposting the same question.
only two letters away from being an asset
|
|
|
|
|
the other post was deleted
|
|
|
|
|
FernandoMartin wrote: i'd like to remove the pointer of the datagridview, i don't know exactly the name of that.
Set the RowHeadersVisible property of the DataGridView to False
|
|
|
|
|
|
how can i code to check for the existence of a particular text file in a drive and then call for a dialogue form if the file does not exist
ma coding life
|
|
|
|
|
Hello,
ploxy wrote: how can i code to check for the existence of a particular text file in a drive
Have a look at System.IO.File namespace and "Exists" method.
ploxy wrote: and then call for a dialogue form if the file does not exist
The System.Windows.Forms.MessageBox with it's static "Show" method will do that.
Hope it helps!
All the best,
Martin
|
|
|
|