Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static byte[] putint(int n)
- {
- byte[] p = new byte[5];
- if(n<128 && n>-127) p[0] = (byte)n;
- else if(n<0x8000 && n>=-0x8000) { p[0] = (byte)0x80; p[1] = (byte)n; p[2] = (byte)(n>>>8); }
- else { p[0] = (byte)0x81; p[1] = (byte)n; p[2] = (byte)(n>>>8); p[3] = (byte)(n>>>16); p[4] = (byte)(n>>>24); }
- return p;
- }
- public static int getint(byte[] p)
- {
- //int c = (char)p[0];
- if (p[0] == -128) { int n = p[1]; n |= (char)(p[2])<<<8; return n; }
- else if (p[0] == -127) { int n = p[1]; n |= p[2]<<<8; n |= p[3]<<<16; return n|(p[4]<<<24); }
- return p[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement