当前位置:网站首页>Decimal to binary
Decimal to binary
2022-06-11 07:12:00 【lihongtao8209】
One 、 explain :
1.R(len,i) The meaning of macros
set up len=8
Sequence R value
i=0 8-0-1=7
i=1 8-1-1=6
i=2 8-2-1=5
i=3 8-3-1=4
i=4 8-4-1=3
i=5 8-5-1=2
i=6 8-6-1=1
i=7 8-7-1=0
2.
test1.txt Deposited
test
Two Chinese characters , As shown in the figure below :
3.
Program compiler code is UTF-8
Two 、 Code
#include<stdio.h>
#include<string.h>
#define R(len,i) (len-i-1)
#define ONE_BYTE 8
char u1[ONE_BYTE+1]="";
char u2[ONE_BYTE+1];
char u3[ONE_BYTE+1];
char path[256]="";
const char* dir="/storage/emulated/0";
const char* file="C4droid/test1.txt";
int makePath(const char* dir,const char* file);
int readFile(char* filename);
void rprint8bits(char* rstr,char* ostr);
void toBinary8Byte(int _1Decimal,char * _8BitStr);
int main()
{
int n=0;
n=makePath(dir,file);
printf("%d,%s\n",n,path);
printf("------------------------\n");
readFile(path);
printf("------------------------\n");
toBinary8Byte(8,u1);
printf("------------------------\n");
rprint8bits(u2,u1);
}
int makePath(const char* dir,const char* file)
{
strcpy(path,dir);
strcat(path,"/");
strcat(path,file);
return strlen(path);
}
int readFile(char* filename)
{
FILE * f;
int i=0;
char cc;
f=fopen(filename,"r");
if(f==NULL)
{
printf("open %s error.\n",filename);
return -1;
}
for(;!feof(f);i++)
{
cc=fgetc(f);
//putchar(cc);
printf("%d %c\n",cc,cc);
}
fclose(f);
}
void toBinary8Byte(int _1Decimal,char * _8BitStr)
{
int i=0;
int quotient=0;
int remain=0;
int decimal=_1Decimal;
memset(_8BitStr,0,sizeof(char)*ONE_BYTE+1);
do
{
quotient=decimal/2;
remain =decimal%2;
_8BitStr[i]=remain;
printf("%d %d [%c]\n",quotient,remain,_8BitStr[i]);
i++;
decimal=quotient;
}while(quotient!=0);
printf("%s\n",_8BitStr);
}
/* rstr reverse string. ostr original string */
void rprint8bits(char* rstr,char* ostr)
{
int i=0;
int len=8;
for(;i<len;i++)
{
rstr[R(len,i)]=ostr[i];
}
for(i=0;i<len;i++)
{
printf("%d",rstr[i]);
}
}
3、 ... and 、 test result 
边栏推荐
- saltstack部署lnmp
- The meaning and research significance of mathematical methodology
- Senior openstacker - Bloomberg, vexxhost upgraded to the Gold member of openinfra Foundation
- Start the Nacos server of shell script
- 12. integer to Roman numeral
- 生物序列智能分析平台blog(1)
- 通过 Ingress 进行灰度发布
- About daily report plan
- Leetcode-9. Palindrome Numbber
- Duality-Gated Mutual Condition Network for RGBT Tracking
猜你喜欢

Duality-Gated Mutual Condition Network for RGBT Tracking

Xunwei dry goods | Ruixin micro rk3568 development board TFTP & NFS writing (Part 1)

Shutter restraint container assembly
![[deploy private warehouse based on harbor] 4 push image to harbor](/img/af/8e28b229d94f3e6eab02308b69dc74.jpg)
[deploy private warehouse based on harbor] 4 push image to harbor

WPF data binding (IV)

Leetcode-141. Linked List Cycle

Analysis of key points and difficulties of ES6 promise source code

模块化笔记

Transformer Tracking

Latex various arrows / arrows with text labels / variable length arrows
随机推荐
Education expert wangzhongze solves students' problems with one move
Explain the difference between void 0 and undefined
Menu double linkage effect in uniapp
Flutter 内外边距
es5和es6的学习小记
Biological sequence intelligent analysis platform blog (1)
一、SQLServer2008安裝(帶密碼)、創建數據庫、C#窗體項目測試
First day of database
Mistakes in Niuke JS exercise
一、SQLServer2008安装(带密码)、创建数据库、C#窗体项目测试
matplotlib的cmap
【CF#697 (Div. 3)】 A - Odd Divisor
Leetcode-141. Linked List Cycle
Interview question 17.08 Circus tower
Error occurred in pycharm DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
Leetcode-9. Palindrome Numbber
【CF#388 (Div. 2)】A. Bachgold Problem
品牌定位个性六种形态及结论的重大意义
顶流编辑器 Atom,将于 12 月 15 日退出历史舞台
[deploy private warehouse based on harbor] 3 deploy harbor