循环打印所有ASCII码的二进制

#include <stdio.h>

void printBinary(int num) {
    for (int i = 7; i >= 0; i--) {
        printf("%d", (num >> i) & 1);
    }
    printf("\n");
}

int main() {
    for(int i = 0; i <= 127; i++) { // 从0到127遍历
        printf("ASCII:%d,字符:%c,二进制:", i, i); // 打印ASCII值和对应的字符(如果可用)
        printBinary(i);
    }
    return 0;
}

 

posted @ 2025-04-02 10:29  华腾智算  阅读(4)  评论(0)    收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL