ord

ord, md5 shows different behaviour on @

人走茶凉 提交于 2021-02-07 10:58:50
问题 I used ord to check @ and @‪ are same char. But ord output the same value while md5 does not. php -a Interactive shell php > echo ord('@'); 64 php > echo ord('@‪'); 64 php > echo md5('@'); 518ed29525738cebdac49c49e60ea9d3 php > echo md5('@‪'); e6124653b6620abe51d7c401a7644674 php > Here is the screenshot, 回答1: Your second one is @ followed by U+202A - LEFT-TO-RIGHT EMBEDDING . As they are different strings, naturally they have different MD5 encodings. php > echo md5("@\u{202a}");

Why does ord() fail when porting from Python 2 to Python 3?

岁酱吖の 提交于 2020-05-29 10:36:26
问题 I am trying to port a Python library called heroprotocol from Python 2 to Python 3. This library is used to parse replay files from an online game called Heroes of the Storm, for the purpose of getting data from the file (i.e. who played against who, when did they die, when did the game end, who won, etc). It seems that this library was created for Python 2, and since I am using Python 3 (specifically Anaconda, Jupyter notebook) I would like to convert it to Python 3. The specific issue I am

Implementing Ord for a type is awkward?

岁酱吖の 提交于 2019-12-30 08:10:37
问题 I have a newtype and I want to implement Ord : use std::cmp::{Ord, Ordering}; struct MyType(isize); impl Ord for MyType { fn cmp(&self, &other: Self) -> Ordering { let MyType(ref lhs) = *self; let MyType(ref rhs) = *other; lhs.cmp(rhs) } } When I try to compare two variables of my types, I get errors: error[E0277]: the trait bound `MyType: std::cmp::PartialOrd` is not satisfied --> src/main.rs:5:6 | 5 | impl Ord for MyType { | ^^^ can't compare `MyType` with `MyType` | = help: the trait `std:

PHP function ord() returns wrong code of cirilyc charecter

余生长醉 提交于 2019-12-25 04:24:09
问题 The utf-8 charcode of Russian 'A' is 1040 (decimal). Javascript do it right: > 'А'.charCodeAt(0) > 1040 But PHP code <?php echo ord('А');?> returns 208. Please note that in the beginning of the PHP code I have: mb_internal_encoding( 'UTF-8' ); setlocale( LC_CTYPE, 'ru_RU' ); How can I implement coding and decoding of UTF-8 characters in PHP? Use another function instead of ord ? 回答1: <?php mb_internal_encoding('UTF-8'); header('Content-Type: text/html; charset=UTF-8'); ?> <html> <head> <meta

ORD and CHR a file in Bash

拟墨画扇 提交于 2019-12-13 10:59:47
问题 I build ord and chr functions and they work just fine. But if I take a file that contains \n , for example: hello CHECK THIS HIT YES when I ord everything I don't get any new line values. Why is that? I'm writing in Bash. Here is the code that I am using: function ord { ordr="`printf "%d\n" \'$1`" } TEXT="`cat $1`" for (( i=0; i<${#TEXT}; i++ )) do ord "${TEXT:$i:1}" echo "$ordr" done 回答1: Your ord function is really weird. Maybe it would be better to write it as: function ord { printf -v

Python - Increment Characters in a String by 1

跟風遠走 提交于 2019-12-08 17:41:41
问题 I've searched on how to do this in python and I can't find an answer. If you have a string: >>> value = 'abc' How would you increment all characters in a string by 1? So the input that I'm looking for is: >>> value = 'bcd' I know I can do it with one character using ord and chr: >>> value = 'a' >>> print (chr(ord(value)+1)) >>> b But ord() and chr() can only take one character. If I used the same statement above with a string of more than one character. I would get the error: Traceback (most

PHP: chr和pack、unpack那些事

眉间皱痕 提交于 2019-12-07 20:47:17
PHP是一门很灵活的语言。正因为它太灵活了,甚至有些怪异,所以大家对它的评价褒贬不一。其实我想说的是,任何一门语言都有它自身的哲学,有它存在的出发点。PHP为Web而生,它以快速上手、快速开发而著称,所以它也常被冠以简单、新手用的语言等标签。我倒不这么认为,所谓选对的工具去做对的事,没有包打天下的语言。而至于说其简单,却也未必。 引子 我之前有篇文详细介绍过pack和unpack: PHP: 深入pack/unpack ,如果有不明白的地方,建议再回过头去看多几遍。现在应该能够写出以下代码: <?php echo pack("C", 97) . "\n"; $ php -f test.php a 但是,为什么会输出'a'呢?虽然我们知道字符'a'的ASCII码就是97,但是pack方法返回的是二进制字符串,为什么不是输出一段二进制而是'a'?为了确认pack方法返回的是一段二进制字符串,这里我对官方的pack的描述截了个图: 确实如此,pack返回包含二进制字符串的数据,接下来详细进行分析。 程序是如何显示字符的 这里所说的'程序',其实是个宏观的概念。 对于在控制台中执行脚本(这里是指PHP作为cli脚本来执行),脚本的输出会写入标准输出(stdin)或标准错误(stderr),当然也有可能会重定向到某个文件描述符。拿标准输出来说,暂且忽略它是行缓冲、全缓冲或者是无缓冲

PHP ord() function on extended ASCII table

笑着哭i 提交于 2019-12-07 19:09:16
问题 I'm facing a weird problem with the PHP ord() function when using it on ASCII characters from the extended ASCII table : <?php echo ord('!'); // prints 33 : OK echo ord('a'); // prints 97 : OK echo ord('é'); // prints 195 : NOT OK echo ord('ü'); // prints 195 : NOT OK ?> Do you have any idea why this function has this behavior ? Moreover i'd like to specify that i'm actually trying to create a really simple steganography program that converts a message character by character into it's binary

The right way to check of a string has hebrew chars

做~自己de王妃 提交于 2019-12-06 14:08:23
问题 The Hebrew language has unicode representation between 1424 and 1514 (or hex 0590 to 05EA). I'm looking for the right, most efficient and most pythonic way to achieve this. First I came up with this: for c in s: if ord(c) >= 1424 and ord(c) <= 1514: return True return False Then I came with a more elegent implementation: return any(map(lambda c: (ord(c) >= 1424 and ord(c) <= 1514), s)) And maybe: return any([(ord(c) >= 1424 and ord(c) <= 1514) for c in s]) Which of these are the best? Or i

PHP ord() function on extended ASCII table

好久不见. 提交于 2019-12-06 03:03:58
I'm facing a weird problem with the PHP ord() function when using it on ASCII characters from the extended ASCII table : <?php echo ord('!'); // prints 33 : OK echo ord('a'); // prints 97 : OK echo ord('é'); // prints 195 : NOT OK echo ord('ü'); // prints 195 : NOT OK ?> Do you have any idea why this function has this behavior ? Moreover i'd like to specify that i'm actually trying to create a really simple steganography program that converts a message character by character into it's binary representation (using the ASCII table) and then creating a simple black and white 8xC pixels image