首页 > 其他分享 >[Code-Palace] 各种数据类型的二进制表示

[Code-Palace] 各种数据类型的二进制表示

时间:2023-01-18 18:22:16浏览次数:48  
标签:Code Palace void 数据类型 number long unsigned fa out

生成的二进制码被保存在"data.exe"文件
请用VS Code中的Hex Editor或其他二进制编辑器查看

#include <stdio.h>
#include <stdlib.h>

void char_out();
void unsigned_char_out();
void short_out();
void unsigned_short_out();
void int_out();
void unsigned_int_out();
void long_out();
void unsigned_long_out();
void long_long_out();
void unsigned_long_long_out();
void float_out();
void double_out();
void long_double_out();
void print_question();
void switch_data_type(char data_type);

int main() {
    print_question();
    char data_type;
    while (scanf("%c", &data_type)) {
        if (data_type == 'q')
            return 0;
        printf("Now enter your number: ")
            switch_data_type(data_type);
        printf("file data.exe has been writen already!\n");
        print_question();
        while (getchar() != '\n') {}
    }
    return 0;
}

void print_question() {
    printf("Please choose a data type:(q to quit)\n");
    printf("1)char      2)unsigned char\n");
    printf("3)short     4)unsigned short\n");
    printf("5)int       6)unsigned int\n");
    printf("7)long      8)unsigned long\n");
    printf("9)long long A)unsigned long long\n");
    printf("B)float     C)double\n");
    printf("D)long double\n");
    printf("Enter your data type: ");
}

void switch_data_type(char data_type) {
    switch (data_type) {
    case '1':
        char_out();
        break;
    case '2':
        unsigned_char_out();
        break;
    case '3':
        short_out();
        break;
    case '4':
        unsigned_short_out();
        break;
    case '5':
        int_out();
        break;
    case '6':
        unsigned_int_out();
        break;
    case '7':
        long_out();
        break;
    case '8':
        unsigned_long_out();
        break;
    case '9':
        long_long_out();
        break;
    case 'A':
        unsigned_long_long_out();
        break;
    case 'B':
        float_out();
        break;
    case 'C':
        double_out();
        break;
    case 'D':
        long_double_out();
        break;
    default:
        break;
    }
    return;
}

void char_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    char number;
    scanf("%hhd", &number);
    fwrite(&number, sizeof(char), 1, fa);
    fclose(fa);
}

void unsigned_char_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    unsigned char number;
    scanf("%hhu", &number);
    fwrite(&number, sizeof(unsigned char), 1, fa);
    fclose(fa);
}

void short_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    short number;
    scanf("%hd", &number);
    fwrite(&number, sizeof(short), 1, fa);
    fclose(fa);
}

void unsigned_short_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    unsigned short number;
    scanf("%hu", &number);
    fwrite(&number, sizeof(unsigned short), 1, fa);
    fclose(fa);
}

void int_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    int number;
    scanf("%d", &number);
    fwrite(&number, sizeof(int), 1, fa);
    fclose(fa);
}

void unsigned_int_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    unsigned int number;
    scanf("%u", &number);
    fwrite(&number, sizeof(unsigned int), 1, fa);
    fclose(fa);
}

void long_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    long number;
    scanf("%ld", &number);
    fwrite(&number, sizeof(long), 1, fa);
    fclose(fa);
}

void unsigned_long_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    unsigned long number;
    scanf("%lu", &number);
    fwrite(&number, sizeof(unsigned long), 1, fa);
    fclose(fa);
}

void long_long_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    long long number;
    scanf("%lld", &number);
    fwrite(&number, sizeof(long long), 1, fa);
    fclose(fa);
}

void unsigned_long_long_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    unsigned long long number;
    scanf("%llu", &number);
    fwrite(&number, sizeof(unsigned long long), 1, fa);
    fclose(fa);
}

void float_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    float number;
    scanf("%f", &number);
    fwrite(&number, sizeof(float), 1, fa);
    fclose(fa);
}

void double_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    double number;
    scanf("%lf", &number);
    fwrite(&number, sizeof(double), 1, fa);
    fclose(fa);
}

void long_double_out() {
    FILE* fa;
    fa = fopen("data.exe", "w");
    long double number;
    scanf("%Lf", &number);
    fwrite(&number, sizeof(long double), 1, fa);
    fclose(fa);
}

标签:Code,Palace,void,数据类型,number,long,unsigned,fa,out
From: https://www.cnblogs.com/fjnhyzCYL/p/17060371.html

相关文章

  • Codeforces Round #834 (Div. 3) A~E泛做
    A.Yes-Yes?构造一个\(N=50\)的字符串,判断是不是子串即可。#include<bits/stdc++.h>usingnamespacestd;#defineendl'\n'#definecerr(x)std::cerr<<(#x)<<......
  • VSCode debug gradle multiple-project 项目
    项目分层(阿里巴巴Java开发手册推荐)Gradle项目在APPproject的build.gradle中配置依赖其他project,执行task会输出到build文件夹默认debug的时候会创建launch.json{......
  • Codeforces Round #740 C
    C.Bottom-TierReversals题链这种翻转方式显然我们是要从后往前固定元素我们先来判断无解情况因为他只允许在奇数位置rev那么我们可以发现每个位置的奇偶性都不会改......
  • C#调用CODESOFT标签打印
    1、创建标签模板2、在C#项目中引用CODESOFT插件在项目中引用软件对应插件,路径见下图"Lppx2.tlb"  添加成功后,在引用中会出现: ......
  • 数据类型的转换
    #数据类型转换#万物皆可转字符串,字符串要想转成数字必须确保字符串里面的内容均是数字才行x=6int(x)#将数字类型转换成字符串num_str=str(11)print(type(num......
  • 数据类型python
    type()语句的用法运行结果......
  • ClickHouse常见数据类型以及常用SQL语法
    文章目录1.数值类型(整形,浮点数,定点数)2.字符串类型3.时间类型4.枚举类型5.布尔值6.其他数据类型7.ClickHouse与Mysql数据类型对比8.常见SQL语法和注意事项1.......
  • Codeforces Global Round 16 E
    E.BudsRe-hanging题链观察样例我们发现我们要尽可能的分解出来bud然后再来组合拼在一起是最优的当然我们可以从深度最深的开始判断是不是bud但是我们再观察发现只......
  • ftp服务无法启动:vsftpd.service: Main process exited, code=exited, status=2/INVALI
    近期使用kali开启ftp服务时出现报错:1.修改配置文件/etc/vsftpd.config:设置如下:listen=YESlisten_ipv6=NO如果自己电脑的当前网络环境支持ipv6的话可以将listen_i......
  • 如果有效python code review
    这篇文章主要介绍一些工具,方法,可以帮助我们做codepre-commit检查,这样我们做codereview之前,这些工具方法就帮我们解决了一些代码风格的问题和静态检查就能检查出来......