Shell script converts decimal data to hexadecimal

Source: Internet
Author: User

This article describes a shell script that handles the conversion of decimal numbers to 16-way. The existing two data files I0.txt and Q0.txt are as follows:

I0.txt Q0.txt

935 3297

385 6964

-280 12697

1768 8404

7377-852

#!bin/bash

#因为有负数, so convert to 16-bit hexadecimal number first%16x

Cat I.txt | \

awk ' {printf '%16x \ n ',} ' > I00.txt

Cat Q.txt | \

awk ' {printf '%16x \ n ',} ' > Q00.txt

#我需要的是i0 the 4-bit hexadecimal number corresponding to the. txt and q0.txt decimal numbers, with a valid 4-bit

Cut-c 13-16 i00.txt > I_mem.txt

Cut-c 13-16 q00.txt > Q_mem.txt

#不足4位的, front 0.

Cat I_mem.txt | \

awk ' {printf '%04s \ n ',} ' > I_mem_00.txt

Cat Q_mem.txt | \

awk ' {printf '%04s \ n ',} ' > Q_mem_00.txt

#将两个文件 (each 4-bit) consists of 8-bit hexadecimal numbers

Paste-d ":" I_mem_00.txt q_mem_00.txt > Rfiu_mem_00.txt

Sed ' s/://g ' rfiu_mem_00.txt > Rfiu_mem.txt

#中间数据如下:

I00.txt Q00.txt

3a7 Ce1

181 1b34

FFFFFFFFFFFFA1F 3199

6e8 20d4

1CDC FFFFFFFFFFFFFCAC

I_mem.txt Q_mem.txt

3a7 Ce1

181 1b34

FA1F 3199

6e8 20d4

1CDC FCAC

I_mem_00.txt Q_mem_00.txt

03a7 0ce1

0181 1b34

FA1F 3199

06e8 20d4

1CDC FCAC

Rfiu_mem.txt

03a70ce1

01811b34

FA1F 3199

06e820d4

1cdcfcac

Note: Perhaps this method is not the most concise, if there is a better way to ask the Master twos, greatly appreciated.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.