当前位置:网站首页>7-4 BCD decryption (10 points)
7-4 BCD decryption (10 points)
2022-07-03 14:14:00 【Big fish】
BCD A number is a two digit decimal number expressed in one byte , Every four bits represent one bit . So if a BCD The hexadecimal number is 0x12, It expresses decimal 12. But Xiao Ming didn't learn BCD, Put all the BCD Numbers are converted into decimal output as binary numbers . therefore BCD Of 0x12 It is output as decimal 18 了 !
Now? , Your program needs to read this wrong decimal number , Then output the correct decimal number . Tips : You can take 18 Convert back to 0x12, And then switch back to 12.
( Make complaints about it , In fact, this topic is 10 Decimal conversion BCD Format alphabetic 16 Base number , Don't be confused by questions )
Extended reading Decimal to hexadecimal C Language explanation _ Learning notes , For reference only -CSDN Blog _c Language decimal to hexadecimal
Here, first explain what is BCD Count :
Decimal 15 BIN Expressed as 1111(BIN In fact, it refers to binary data , Meet 2 Just write forward 1, Change the original position to zero , The number that has been written according to this rule )
BCD In fact, it means Write a number in groups of binary numbers , such as :
Decimal 15 BCD Expressed as 0001 0101
Input format :
Input gives a... In one line [0, 153] Positive integer in range , Ensure that it can be converted back to a valid BCD Count , In other words, this integer will not appear when converted to hexadecimal A-F The number of .
Output format :
Output the corresponding decimal number .
sample input :
18
sample output :
12
Reference code
#include <stdio.h>
int main()
{
int n, cnt = 0, t = 1, num = 0;
int s[2];
scanf("%d", &n);
// Decimal to hexadecimal
while (n)
{
s[cnt] = n % 16;
t *= 16;
n /= 16;
cnt++;
}
if (s[1] != 0)
printf("%d", s[1]);
printf("%d\n", s[0]);
return 0;
}Another way to do it
#include <stdio.h>
int main()
{
int i,j,k;
scanf("%d", &i);
j = i / 16;
k = i % 16;
printf("%d\n", j*10+k);
return 0;
}
边栏推荐
- [clean up the extraordinary image of Disk C]
- 7-9 find a small ball with a balance
- Exercise 10-3 recursive implementation of exponential functions
- Learn to punch in today
- 556. 下一个更大元素 III
- Installation impression notes
- Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
- 八大排序
- 可编程逻辑器件软件测试
- How to bold text in AI
猜你喜欢

protobuf与grpc

QT learning 22 layout manager (I)

JS Part III

Solution to failure or slow downloading of electron when electron uses electron builder to package

Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值

Exercise 9-3 plane vector addition

JS Part 2

UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料

Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material

Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
随机推荐
别再问自己适不适合做软件测试了
Vite project commissioning
MongoDB索引
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Raft 协议
Print. JS -- web page file printing
Learn to punch in today
The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
JS general form submission 1-onsubmit
Eight sorts
etcd集群权限管理和账号密码使用
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
Message subscription and publishing
Article content typesetting and code highlighting
C language,%d% Difference between 2D%2d%02d
QT learning 17 dialog box and its types
Too many files with unapproved license