| |

VerySource

 Forgot password?
 Register
Search
View: 734|Reply: 8

Help: About coding

[Copy link]

1

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-2-3 17:00:01
| Show all posts |Read mode
For example, now there is a "test" word. Its UNICODE ASCII code is 27979. Hexadecimal ASCII code is 6D4B.

Now I want to convert it to GBK internal code, that is, to get the GBK ASCII code of "test" word: 45794, and then I convert it to hexadecimal. . . I ask everyone how to get the ASCII code of the GBK internal code of Chinese characters?

Thank you
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-3-22 18:45:01
| Show all posts
char a = 'Measure';
System.out.println (Integer.toHexString (((int) a)));
System.out.println ((int) a);
byte [] b = new String ("测") .getBytes ("gbk");
int i = b [1] << 4;
i = i | b [0];
a = (char) i;
System.out.println (Integer.toHexString (((int) a)));
System.out.println ((int) a);
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-23 14:45:01
| Show all posts
Slow a beat,
When String.getBytes seems to throw UnsupportedEncodingException.
Reply

Use magic Report

1

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-24 14:45:01
| Show all posts
tozzzdsd

It's impossible, brother
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-4-1 14:15:01
| Show all posts
Ha ha, I do n’t think it is right

Rewritten

        public static String getGBK (String a) throws UnsupportedEncodingException {
    byte [] b = new String (a) .getBytes ("gbk");
    String b1 = Integer.toString ((char) b [0], 16) .toUpperCase ();
    String b2 = Integer.toString ((char) b [1], 16) .toUpperCase ();
    return b1.substring (2,4) + b2.substring (2, 4);
     }
     public static int getGBKINT (String a) throws UnsupportedEncodingException {
    String tmp = getGBK (a);
    return Integer.parseInt (tmp, 16);
     }

test
String a = "测";
System.out.println (getGBK (a));
System.out.println (getGBKINT (a));
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 United States

Post time: 2020-4-14 11:15:01
| Show all posts
I finally realized that my first wording was wrong, and the number of digits and high status were wrong.
                  char aa = 'Measure';
byte [] b = new String ("Test"). getBytes ("gbk");
int high = b [0] << 8&0xFFFFFF00;
int low = b [1]&0xFFFF00FF;
int gbk = (high | low)&0x0000FFFF;
System.out.println (Integer.toHexString ((gbk)));
System.out.println (gbk);
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-4-14 12:15:01
| Show all posts
char aa = 'Measure';
byte [] b = new String ("Test"). getBytes ("gbk");
int high = b [0] << 8&0xFFFFFF00;
int low = b [1]&0xFFFF00FF;
int gbk = (high | low)&0x0000FFFF;
System.out.println (Integer.toHexString ((gbk)));
System.out.println (gbk);
Reply

Use magic Report

1

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 United States

 Author| Post time: 2020-4-16 21:00:02
| Show all posts
Conversely, decoding is not that simple. .
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-4-16 23:15:01
| Show all posts
Yes, the getbyte function is actually very powerful
But the converse is also the same, mainly need to check the information, check the area corresponding to unicode and gbk
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list