English 中文(简体)
Read
原标题:Reading byte and mask it in java

我应从记本中拿到身份证,但该法典没有给出正确的说法。 谁能告诉我,我的法典中有什么错误? (详情见下文)

for (int i = 0; i < numberOfSRecords; i++) {
    socketReader.read(cbuf, 0, 4);
    String Param_Codes_In_HEX =
        Integer.toHexString(0x000000ff & cbuf[2]) +
        Integer.toHexString(0x000000ff & cbuf[1]) +
        Integer.toHexString(0x000000ff & cbuf[0]);
    System.out.println("Param_Codes_In_HEX: "+Param_Codes_In_HEX);
    int paramCode = Integer.parseInt(Param_Codes_In_HEX, 16);
    if ((0x000000ff & cbuf[3]) ==0) {
    EnumParamCodes enumParamCode = 
         EnumConverterUtil.getEnumFor(EnumParamCodes.class, paramCode);
    System.out.println("Param_code " + paramCode + ": " + enumParamCode);
    }
  else if((0x000000ff & cbuf[3]) ==64)
   {
    paramCode = 0x0000ffff & paramCode ;
    EnumParamCodes enumParamCode = EnumConverterUtil.getEnumFor(EnumParamCodes.class, paramCode);
   System.out.println("Param_code " + paramCode + ": " + enumParamCode);
   }
  else if ((0x000000ff & cbuf[3]) ==128) {
      paramCode = 0x00ffffff & paramCode ;
      EnumAlarm enumParamCodeAlarm = EnumConverterUtil.getEnumFor(EnumAlarm.class, paramCode);
      System.out.println("Param_code " + paramCode + ": " + enumParamCodeAlarm);
    } 
  else{
      System.out.println("Error in the body of message");
        }
      }

Note: • For Numerical and Enumerative Parameters (ActualValue), the Param_code corresponds to the ID in the Parameters section

• For Numerical and Enumerative Parameters (SetValue), the Param_code corresponds to 0x40000000 + the ID in the Parameters section

• For Alarm Parameters, the Param_code corresponds to 0x80000000 + the ID in the Parameters section

最佳回答
String getByteString(byte b) {
    StringBuffer buf = new StringBuffer();
    String digit=Integer.toHexString(b &0xff);
    buf.append(digit);
    if (digit.length()<2) buf.append( 0 );
    return buf.toString();
}

这应当为你们带来 0。

String Param_Codes_In_HEX = getByteString(cbuf[2]) + getByteString(cbuf[1]) + getByteString(cbuf[0]);
问题回答

守则对于它正在做的事情来说相当复杂。 其中一个问题是,在你想要做比喻的操纵时,可能会试图进行分类。 e. 例如,1 233先令将变成123而不是010203。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签