Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
namespace sonar_proj
{
    public partial class son : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

       char[] a = new char[10];
       char y  = conversion(byte );
        private byte conversion(byte binval)
        {
            binval =(byte)~binval;
            byte temp = (byte)(((binval & 0xf0)>>4) |(byte)((binval &0x0f)<<4) );
            return temp;
        }




         its showin some error . can u plz sort out this error
Posted
Comments
Prasad_Kulkarni 23-Apr-12 2:54am    
What error you're getting Rahul??
Rahul_Chand 23-Apr-12 2:59am    
Error 2 Invalid expression term 'byte'...this is error im gettin prasad.
Sandeep Mewara 23-Apr-12 3:07am    
What do you mean by:
char y = conversion(byte );
Rahul_Chand 23-Apr-12 3:11am    
Sandeep actually I want to pass some binary numbers e.g 11010011

1) You can't declare a method in the middle of another method.
Move it outside the Page_Load event, and all should be fine.

2) You can't pass a class byte as a parameter to your conversion routine - you need to pass a value instead.
 
Share this answer
 
Comments
Rahul_Chand 23-Apr-12 3:13am    
Can you please tell me how to send the values ???
OriginalGriff 23-Apr-12 3:27am    
byte b = 123;
char y = (char) conversion(b);

You need to cast the conversion return value to a char or the compiler will rightly complain!
Rahul_Chand 23-Apr-12 3:30am    
Its again throwing eror called Error 1 Expected class, delegate, enum, interface, or struct
OriginalGriff 23-Apr-12 3:34am    
You have probably put the code in the wrong place! Check your code: comment out those two lines so that it compiles clean - it won't work yet, but as soon as it compiles cleanly press CTRL+K CTRL+D which should reformat your whole document so that the indentation is correct. These two lines of code need to be inside the "{" and "}" immediately following the

protected void Page_Load(object sender, EventArgs e)
Rahul_Chand 23-Apr-12 3:44am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace sonar_proj
{
public partial class son : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

char[] a = new char[10];
byte b = 123;
char y = (char) conversion(b);
}
private byte conversion(byte binval)
{
binval = (byte)~binval;
byte temp = (byte)(((binval & 0xf0) >> 4) | (byte)((binval & 0x0f) << 4));
return temp;
}
}

}
this is my program . Still Iam able to bug the error . Can u tell me why is its so.
Read about Byte here: MSDN: Byte[^]

Example:
C#
byte myByte = 255;

// For your program
char y  = conversion(myByte);
 
Share this answer
 
Comments
Rahul_Chand 23-Apr-12 3:22am    
Sandeep thnks for your concern but even though by adding byte myByte = 255;

// For your program
char y = conversion(myByte); I am gettin the error called Error 1 Expected class, delegate, enum, interface, or struct
char is for characters. byte is for numbers. From what I have read here, you're dealing with numbers only. So forget about char completely for now and change it all to byte.

Then you have
C#
byte y  = conversion(byte );
, which doesn't work because you pass a type as parameter where a value of type byte is expected. Change to
C#
byte y = conversion(0x42);
.

The "42" represents some value. I don't know what you really want to convert. Put whatever you want between the brackets of convert().
 
Share this answer
 
Comments
Rahul_Chand 23-Apr-12 3:28am    
I edited but its not workin so .
lukeer 26-Apr-12 2:49am    
Edit your question using the "Improve question" link.
Show the relevant code. Mark where an error is reported.
Show the exact error message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900