Sponsored Content
Top Forums Shell Programming and Scripting Conversion from Hexadecimal to binary Post 302892816 by aydj on Friday 14th of March 2014 03:31:49 PM
Old 03-14-2014
Code:
/usr/xpg4/bin/awk  '
function bits2str(bits,        data, mask)
     {
         if (bits == 0)
             return "0"

         mask = 1
         for (; bits != 0; bits = rshift(bits, 1))
             data = (and(bits, mask) ? "1" : "0") data

         while ((length(data) % 1) != 0)
             data = "0" data

         return data
     }

     {for(i=5;i<=NF;i++)$i = bits2str(strtonum("0x"$i))}1' t.log

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script conversion to binary

My question is: i have a script called getevent to run i just call ./getevent can i convert this to make it binary executable and not letting my clients open it and see the code.??:( I am using Solaris 8. (3 Replies)
Discussion started by: bcheaib
3 Replies

2. UNIX for Dummies Questions & Answers

Binary file conversion

All, I want to convert multiple \0 005 characters to line feed 012 character in a binary file to make to readable. Here is the sample od -c file output: 0000000 254 355 \0 005 s r \0 * c o m . c i s c Here is the sample od -b file output: 0000000 254 355 000... (0 Replies)
Discussion started by: bubba112557
0 Replies

3. Shell Programming and Scripting

Decimal to Hexadecimal conversion

Hi frnds :) I need a small help... I have a very long file containing 20 digits decimal number which i want to convert into the corresponding 16 digit hexadecimal values. File looks like.... 11908486672755551741 05446378739602232559 04862605079740156652 . . . I tried the script for i... (7 Replies)
Discussion started by: vanand420
7 Replies

4. Programming

Binary conversion function

Is/are there any function(s) in C that convert(s) character/ASCII/Decimal to binary and vice versa? what about bcopy and strcpy? (1 Reply)
Discussion started by: Peevish
1 Replies

5. Shell Programming and Scripting

binary file conversion

Hello folks, i have a binary text file but i am not able to convert into text format, please suggest. thanks. (2 Replies)
Discussion started by: learnbash
2 Replies

6. Shell Programming and Scripting

binary to ascii conversion

Hi, I have got a library file, created by compiling C code. The file information with "file" command, gives it a "application/x-archive" type file. I want to extract the release string of my software from this file, so that i can know which version of C files were used to create the lib. Can... (3 Replies)
Discussion started by: atulmt
3 Replies

7. Solaris

binary conversion

Why would a binary which was compiled on a Solaris-10 not be runnable in a SunOS 5.10? (they are supposed to be precisely equivalent). When I run the file command on it, it says: ELF 32-bit LSB executable 80386 Version 1, dynamically linked, not stripped, no debugging information available... (10 Replies)
Discussion started by: steve701
10 Replies

8. Shell Programming and Scripting

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there. I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies

9. Shell Programming and Scripting

Hexadecimal to Binary conversion

Hi Guys, Is it possible to convert the hexadecimal to Binary by unix command.....I could not figure out.... If I need to convert AF6D to binary...what could be the way to do? Thanks in advance!! ---------- Post updated at 02:57 AM ---------- Previous update was at 02:42 AM ---------- I... (6 Replies)
Discussion started by: Indra2011
6 Replies

10. Programming

Hexadecimal to binary operation

Dear all, I am trying to write c-program to read the following file containing hexadecimal values (snippet of big data file). I want to combine two hexadecimal values together like A0A03E01 and then would like to have the binary equivalent to perform further test on it. Unfortunately, it failed... (16 Replies)
Discussion started by: emily
16 Replies
BITS(3) 						   BSD Library Functions Manual 						   BITS(3)

NAME
__BIT, __BITS, __SHIFTIN, __SHIFTOUT, __SHIFTOUT_MASK -- macros for preparing bitmasks and operating on bit fields SYNOPSIS
#include <sys/param.h> #include <sys/cdefs.h> uintmax_t __BIT(n); uintmax_t __BITS(m, n); __SHIFTIN(v, mask); __SHIFTOUT(v, mask); __SHIFTOUT_MASK(mask); DESCRIPTION
These macros prepare bitmasks, extract bitfields from words, and insert bitfields into words. A ``bitfield'' is a span of consecutive bits defined by a bitmask, where 1s select the bits in the bitfield. Use __BIT() and __BITS() to define bitmasks: __BIT(n) Return a bitmask with bit n set, where the least significant bit is bit 0. __BITS(m, n) Return a bitmask with bits m through n, inclusive, set. It does not matter whether m > n or m <= n. The least significant bit is bit 0. __SHIFTIN(), __SHIFTOUT(), and __SHIFTOUT_MASK() help read and write bitfields from words: __SHIFTIN(v, mask) Left-shift bits v into the bitfield defined by mask, and return them. No side-effects. __SHIFTOUT(v, mask) Extract and return the bitfield selected by mask from v, right-shifting the bits so that the rightmost selected bit is at bit 0. No side-effects. __SHIFTOUT_MASK(mask) Right-shift the bits in mask so that the rightmost non-zero bit is at bit 0. This is useful for finding the greatest unsigned value that a bitfield can hold. No side-effects. Note that __SHIFTOUT_MASK(m) = __SHIFTOUT(m, m). EXAMPLES
The following example demonstrates basic usage of the bits macros: uint32_t bits, mask, val; bits = __BITS(2, 3); /* 00001100 */ mask = __BIT(2) | __BIT(3); /* 00001100 */ val = __SHIFTIN(0x03, mask); /* 00001100 */ val = __SHIFTOUT(0xf, mask); /* 00000011 */ SEE ALSO
bitops(3), cdefs(3) HISTORY
The bits macros first appeared in atw(4), with different names and implementation. In their current form these macros appeared in NetBSD 4.0. AUTHORS
The bits macros were written by David Young <dyoung@NetBSD.org>. Matt Thomas <matt@NetBSD.org> suggested important improvements to the implementation, and contributed the macro names SHIFTIN() and SHIFTOUT(). BUGS
__BIT() and __BITS() can only express 32-bit bitmasks. BSD
October 17, 2012 BSD
All times are GMT -4. The time now is 08:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy