|
The sign is represented by the MSb (most significant bit).
Binary Hex byte sbyte
00000000 0x00 0 0
...
01111111 0x7F 127 127
10000000 0x80 128 -128
...
11111111 0xFF 255 - 1
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
modified on Saturday, June 5, 2010 9:09 AM
|
|
|
|
|
Because a sbyte is a "short byte", meaning it's max value is half of what a normal byte would hold. In your case, your value is causing an interger overflow condition, and the value becomes -1.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I thought the 's' stood for signed rather than short as it's still 8 bits so no shorter.
Either way the answer to the OP is the same and correct
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
You're right, however if we are going to be picky, maybe you'd better fix the mistake in
10000000 0x80 128 -127
too?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
Long ago Data General used to build 36-bit machines, where an integer by default was 36 bits; they also had instructions that treated registers holding five 7-bit "bytes" plus a single flag. They used that for representing text, based on ASCII characters, which requires 7 bits. That could rightfully be called short bytes.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
How to handle bit lengths for types values that don't require all of them or require more is still an issue in some situations.
In my MIDI exploits I'm working with 16bit PICs at the moment. The choice between the complexity and therefore instruction cycle overhead of storing 2 bytes in one word (made more complex as packets can be variable lengths so won't always be word aligned) and the waste of scarce resources by ignoring 8 bits for every byte I need to buffer is one I'm still debating.
MS[^] use one 32bit int (all packets, except SysEx which is easy to identify, are 1 to 3 bytes) and 'waste' between 8 and 24 bits each time. Fine on a PC but not efficient useage of RAM on a µC with only 2KB RAM when requiring 4 individual buffers.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I tend to first take care of whatever resource is most scarce. On miniature systems that would be memory most of the time. So decide on a clever data scheme, then come up with efficient accessor functions, even if that takes some ugly code and hacks. Maybe create a stream-like object?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
the 100...00 bit pattern happens to be the only one you can't represent the absolute value of; and lots of run-time libraries don't treat it well, e.g. an sprintf-like function turning a signed integer to its decimal string representation wants to do:
if (value) {
emit('-');
value = -value;
}
which isn't correct, as value may still be negative yielding unexpected quotient/remainder values later on.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I saw that too. That led me to revisit the two's-complement calculation and I found this[^].
"the universe is twos-complement"
Cheers
I don't like my signature at all
|
|
|
|
|
Hello:
I have a MDIParent Form called ICEPack and many MDIChild Forms. For now I am working on the Forms called FormGeneral and FormProduct. When I get these working, then all the rest will be simple. I have a Class called ClassControl where I put all my Controls.
For example... The TextBox events: In ClassControl. This way all my Forms use the same code.
while (TheControlEvent != null)
{
TheEvent = TheControlEvent.GetType().Name;
switch (TheEvent)
{
#region TextBox
case "TextBox":
TheControlEvent.Enter += new EventHandler(TextBoxEnter);
TheControlEvent.Leave += new EventHandler(TextBoxLeave);
TheControlEvent.MouseHover += new EventHandler(TextBoxMouseHover);
TheControlEvent.MouseLeave += new EventHandler(TextBoxMouseLeave);
break;
#endregion
... other code
Before the 'while' I add the following:
TheForm.Enter += new EventHandler(FormEnter);
So there will be only one routine for all Form Enter.
Currently in the MDIChild I have:
public void FormGeneral_Enter(object sender, EventArgs e)
{
FormICEPack.RunAs = RunAs;
FormICEPack.dataGridViewRecord.DataSource = DataTableRecord;
FormICEPack.dataGridViewRecord.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
And would like to put this in the ClassControl:
private void FormEnter(object sender, EventArgs e)
{
// Original code from FormGeneral & FormProduct
//FormICEPack.RunAs = RunAs;
//FormICEPack.dataGridViewRecord.DataSource = DataTableRecord;
//FormICEPack.dataGridViewRecord.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
// New code???
//...
Form TheParentForm = Form.ActiveForm; // Get The Parent Form
TheChildForm = TheParentForm.ActiveMdiChild.Name.ToString(); // Get The Child Form
Assembly oAssembly = Assembly.GetEntryAssembly();
Form oForm = (Form)oAssembly.CreateInstance("ICEPack." + TheChildForm + "()");
String RunAs = (String)oForm.Controls.Find("RunAs", true)[0].ToString(); //<<< ERROR
}
|
|
|
|
|
You can either make the control public (not good practice), or create a public property that returns the value of a control in the form.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hello:
If you look at my code... the part that does not work is:
String RunAs = (String)oForm.Controls.Find("RunAs", true)[0].ToString(); // ERROR
Ok, seems you are saying that I should NOT do it this way.
At the point at:
Form TheParentForm = Form.ActiveForm; // Get The Parent Form
TheChildForm = TheParentForm.ActiveMdiChild.Name.ToString(); // Get The Child Form
"TheChildForm" is the good value of the name of the Form. I need to get the value of the string RunAs" in the Form "TheChildForm".
Can you show me an example of code to do it?
|
|
|
|
|
Hello every one.
First of all I am sorry which put this question here, cause it is not relevant to this part. frankly, I couldn't find any proper forum.
I wana write and database application which run on Iphone. I don't know who to start Iphone programming. does any one any article or any experience and help me in this matter.
What do I need to start an Iphone application programming. which environmnet I can write the codes.
Please help me!!!!!
|
|
|
|
|
you would need 10 things: an iPhone, a Mac, intelligence, programming experience, a good command of Objective C, excellent Google fu, one or more good ideas, stamina, perseverance, and time.
If you score less than 5 right now, I suggest you drop the idea.
PS: you wouldn't need C#
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
You forgot luck of the gods and perhaps a small sacrifice to get the app approved.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I didn't want to discourage the chap.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I am trying to add a new feature to my app written in C#.
I have just begun exploring "remoting" as a solution for a particular problem. It looks like quite a learning curve, so I thought I would ask some experts before spending a lot of time and discovering what I want to do is not possible.
Can you "remote" a windows control like the FolderBrowsingDialog? What I want to do is see the dialog on my PC, but actually be browsing folders on the remote PC.
|
|
|
|
|
Remoting is not going to help you with this.
You can use the dialog, if you have access to the system, and browser the UNC path of the machine, \\MySystem. However, if no folders are shared or you don't have access to the roots (\\MySystem\C$), nothing is going to help.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
If it's the standard File Open dialog, it will allow you to browse machines it can find on the network. If you have the machine name/IP of the machine in question, you can probably send data to that ip/port and any app listening on that port would be able to respond/receive the data you're sending. You may also bup into permissions issues, especially if we're talking about Vista or Weven.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Perhaps more information would clarify what I am trying to do:
I have a C# server application that runs on a dedicated headless PC at a remote location. Actually 5 of them at different locations. The server monitors specific files in specific shares on other systems on the local LAN. I monitor these servers from a central point. This works great.
The problem:
Sometimes things change on the remote LAN. New systems are added or existing systems are removed. I need to be able to modify the monitoring configuration to add/change/delete the monitored folders as necessary.
From the desktop it would be easy, just use a file FolderBrowsingDialog, find the new system and add "\\NewHost\Share\Folder" to the database. For various reasons I can't use RemoteDesktop so doing this from 200 miles away is problematic...
My first thought was to add a few commands to our communications protocol so I could send a command to the monitoring system to get the network host, then get the shares, then get the folders, etc. In my rough outline this got complicated quickly starting with how do you even get a list of the available hosts on the local LAN... I found some articles, but clearly this is going to be a lot of work for a relatively simple task.
My second thought was remoting. I have never done remoting so again I looked for some examples. Another learning curve but seems less problematic than dealing with manually browsing the network.
The object I would like to remote is the standard FolderBrowsingDialog, like the File Open dialog, but just to pick a folder. I want to have the dialog appear on my screen from my client application, but be browsing the servers LAN 200 miles away.
|
|
|
|
|
This is a logistical nightmare.
Is your application a windows service? I suspect that it is (since the machines are headless), but if not, it should be. The service itself can regularly scan for new shares without explicitly being told to do so. When it detects a new share, it can simply start watching for files in the specified folder (if/when it exists). All that has to happen is that the share needs to be established by the remote admin (or you remotely).
If you don't want it to automatically scan for new shares, you can send it data with the share info, and it can save that info in a data file to be retrieved in the event of a hardware restart.
You could use remoting for that, but I think it would be simpler to just send the info via your existing mechanism.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I have a class and two form in my project
i want to validate a filed from form1 and use this field's value in form2
but when i want to use it i cant't access to this value becuase every
time that i new ، object from class filed's value was destroyed
how can i do that ?
|
|
|
|
|
I think you need to post some code here.
I'm sure once you do that someone will be able to help you.
In the meanwhile, also check if the singleton pattern can help you in anyway.
My signature "sucks" today
|
|
|
|
|
class class1
{
public int a;
}
form1 :
class1 s=new class1();
s.a=10
form2:
class1 c=new class1();
messageBox.show(c.a.tostring()); // I want to see 10 here
|
|
|
|