标签: binary

为什么个数的补码表示比其他的更好?

似乎有符号数字的补码表示现在是最流行的(并且可能是现代硬件中使用的唯一表示)。为什么它比其他人更好?

math binary ones-complement

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

在 C:ftell 中读取二进制文件返回的结果有时会相差一位

我正在尝试读取以下格式的二进制文件:

图像数量 [4 字节整数]

width [4-byte int]
height [4-byte int]
灰度数据 [width * height bytes]
(同一类型的更多元素)

这是被调用的第一个函数:

int process_file(const char *filename) {
    FILE *input_file = fopen(filename, "r");

    //Get number of images
    unsigned int number_of_images = read_int_from_file(input_file);

    //Allocate memory for all images
    struct image *images = malloc(sizeof(struct image) * number_of_images);

    read_images(images, number_of_images, input_file)
}
Run Code Online (Sandbox Code Playgroud)

这是image任何想知道的人的结构:

struct image {
    unsigned int width;
    unsigned int height;
    unsigned char *data;
};
Run Code Online (Sandbox Code Playgroud)

这就是它的read_int_from_file作用:

static unsigned int read_int_from_file(FILE *file) {
    unsigned char …
Run Code Online (Sandbox Code Playgroud)

c binary

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

将 string 转换为 const char* (带有二进制数据)

我想要做的是将字符串转换为 const char*。

\n\n

理想情况下,我可以只使用“const char* myConstChar = myString.c_str()”,但如下面的示例所示;它不适用于二进制数据:

\n\n
#include <iostream>\n#include <fstream>\n#include <stdio.h>\n#include <string.h>\n\nusing namespace std;\n\nint main(){\n    string myString;  // This need to be string\n    ifstream infile;\nconst char* myConstChar;  // This need to be const char*\n\ninfile.open("binary.bin");\n\nif(infile){\n        while(getline(infile, myString)){ \n        std::cout << "Data: " << myString << " string length: "; \n            std::cout << myString.length() << "\\n";\n            myConstChar = myString.c_str();\n            std::cout << "const char Data: " << myConstChar; \n            std::cout << " const char length: "<< strlen(myConstChar) <<"\\n";\n        }\n    }\n\n …
Run Code Online (Sandbox Code Playgroud)

c++ binary

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

二进制处理器如何区分两个相同字节大小的变量类型

我想弄清楚两个变量类型如何具有相同的字节大小?

如果我有一个变量,大小为一个字节。计算机如何判断它是一个字符而不是布尔类型变量?或者甚至是一个字符或半个短整数?

c c++ variables binary types

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

二进制序列化对象作为文件的压缩级别

在我的应用程序中,我有一个从一些 XML 文件创建的相当大的对象。xml 文件大小约为 30MB,而该 xml 文件中的二进制序列化对象约为 8~9MB。有趣的是,如果我用 WinRar 等压缩这个二进制文件,它只有 1~2MB。

有没有办法提高对象本身的压缩级别?或者我应该通过手动编写代码来使用另一级压缩,以便在保存后压缩文件或在加载回程序之前解压缩文件?

以防万一,这是我用来将对象保存为文件的代码:

    public static bool SaveProject(Project proj, string pathAndName)
    {
        bool success = true;
        proj.FileVersion = CurrentFileVersion;

        try
        {
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream(pathAndName, FileMode.Create, FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, proj);
            stream.Close();
        }
        catch (Exception e)
        {
            MessageBox.Show("Can not save project!" + Environment.NewLine + "Reason: ", "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            success = false;
        }

        return success;
    }
Run Code Online (Sandbox Code Playgroud)

更新 我尝试通过添加来更改我的代码GZIPSTREAM,但似乎它没有做任何事情!或者也许我的实现是错误的?

public static bool SaveProject(Project proj, string …
Run Code Online (Sandbox Code Playgroud)

c# compression binary serialization winforms

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

小数转换为二进制 - 如何转换 0.1?

我很好奇将小数 0.1 转换为二进制。

如果我有其他小数,我知道一种方法可以做到这一点 - 例如 0.75

1) 0.75 * 2 = 1.5 >= 1 - 然后变成1

2) 0.5 * 2 = 1 >= 1 - 然后变成1

二进制结果:0,11

但如果小数是0.1——如何应用这个方法呢?

1) 0.1 * 2 = 0 < 1则变为0

就变成0了,没有别的了

binary

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

如何计算Python中二进制字符串中连续重复出现的1/0块的数量

例如,我希望代码为输入“01000110”返回“5”,因为重复出现的数字块是“0”、“1”、“000”、“11”、“0”。我想不出解决这个问题的方法。感谢所有帮助/评论。

python string binary

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

什么函数设置“program_incall_name”?什么时候?

这是我得到的一些信息program_invocation_name

  • 该值包含用于调用调用程序的名称。
  • 该值是自动初始化的。
  • 该值是全局变量。
    所以乍一看,我以为它在<.bss>or中<.data>
    但它在stack内存区域中。这很奇怪......


这是调试器视图program_invocation_name

pwndbg> x/s program_invocation_name
0xbffff302: "/tmp/my_program"
Run Code Online (Sandbox Code Playgroud)


问题)

我从程序开始到结束都遵循执行流程,但我找不到设置的那一刻。program_invocation_name


问题)

Q1 . 谁(什么函数)设置了这个值?(loader设置这个值..?)
Q2global variable尽管该值位于 ? 中,但程序如何知道将其识别为stack
Q3 . 有时,某些二进制文件运行时没有此值。在这种情况下,问题是loader

binary x86 assembly executable elf

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

如何在C中将16位值拆分为两个8位值

我不知道这个问题是否正确,但是。

例如,十进制为25441,二进制为110001101100001。我如何将它分成两个8位“1100011”和“01100001”(即“99”和“97”)。然而,我只能想到使用位操作将其移动>>8,而我无法对“97”执行其余操作。这是我的功能,这不是一个好的功能,但我希望它有所帮助:

void reversecode(int input[], char result[]) {  //input is 25441
int i;
for (i = 0; i < 1; i++) {  
    result[i] = input[i] >> 8;                  // shift by 8 bit
    printf("%i", result[i]);                    //to print result
}
}
Run Code Online (Sandbox Code Playgroud)

我正在考虑使用 struct 但我不知道如何启动它。我是 C 语言的初学者,很抱歉我的糟糕风格。谢谢你之前。

c binary bit-manipulation

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

使用按位运算符时出现分段错误

我目前正在搞一个 C 项目,它将接收两个 8 位二进制数并将它们转换为十进制值。我对 C 中的按位运算符以及它们如何处理数字有很好的理解,我的问题是围绕语法的问题。

ATM我的程序很简单:

int main() {
  char *inp1;
  char *inp2;
  unsigned long binNum1;
  unsigned long binNum2;

  printf("Enter the first binary number: "); 
  scanf("%s", inp1); 
  printf("Enter the second binary number: "); 
  scanf("%s", inp2); 

  binNum1 = strtoul(inp1, NULL, 2);
  binNum2 = strtoul(inp1, NULL, 2);

  unsigned long orVal = binNum1 | binNum2;
  unsigned long andVal = binNum1 & binNum2;
  unsigned long exclVal = binNum1 ^ binNum2;

  printf("Your or value is: %lu", orVal);
  printf("Your and value is: %lu", andVal); …
Run Code Online (Sandbox Code Playgroud)

c binary bit-manipulation decimal

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