小编Dic*_*ick的帖子

将整数值转换为字符串

下面是将整数值编码为ASCII字符串的代码.它是用Python编写的,从我的测试中可以正常工作.

def encode(value):
    code = ''
    while value%254 != value:
       code = code + chr(value%254)
       value = value/254
    code = code + chr(value)
    return code

def decode(code):
    value = 0
    length = len(code)
    for i in range(0,  length):
        print code[i]
        value = value * 254 + ord(code[length-1-i])
    return value


code = encode(123456567)
print code

print decode(code)
Run Code Online (Sandbox Code Playgroud)

但是,当我在Lua中尝试相同的实现时,编码和解码的值不匹配.这是我的Lua版本:

function encode(value)
    code = ''
    while value%254 ~= value do

        code = code .. string.char(value%254)
        value = value/254
    end
    code = code .. …
Run Code Online (Sandbox Code Playgroud)

string lua ascii

4
推荐指数
1
解决办法
996
查看次数

如何将变量传递给 cmake 脚本

我正在尝试将变量传递给 cmake 脚本,但显然我没有正确执行。我正在尝试按照教程构建一个计时项目。我正在关注的教程在这里:

https://api.projectchrono.org/tutorial_install_project.html

CMakeLists.txt 修改如下:

#--------------------------------------------------------------
# 
# Example of CMake configuration file to build an external 
# project depending on Chrono and on optional Chrono modules.
# 
# This minimal sample project can be used as a template for a
# user project.  Modify sections 1, 2, and 3 below as appropriate.
# 
#--------------------------------------------------------------
 

cmake_minimum_required(VERSION 2.8)

#--------------------------------------------------------------
# === 1 === 
# Modify the project name if you want: 
#--------------------------------------------------------------

project(my_project)

#--------------------------------------------------------------
# === 2 ===
# Find …
Run Code Online (Sandbox Code Playgroud)

c++ configuration cmake

0
推荐指数
1
解决办法
1460
查看次数

标签 统计

ascii ×1

c++ ×1

cmake ×1

configuration ×1

lua ×1

string ×1