Converting HexDecimal To Binary - 'C' programming


 
Thread Tools Search this Thread
Top Forums Programming Converting HexDecimal To Binary - 'C' programming
# 1  
Old 03-19-2009
Converting HexDecimal To Binary - 'C' programming

guys,

Can somebody help me with a Unix 'C' program, to convert the Hexa decimal value to binary value.


Thank you
Cheers Smilie
S
# 2  
Old 03-19-2009
Homework? What exactly are the requirements? Just output 1s and 0s?

I'd start with some consistency checks on the input (even number of characters, all between 0 and F), sscanf() 2 characters at a time into an unsigned char, loop over the byte with a bitwise AND, shifting the mask right at every iteration, and output a '1' or '0' as needed. Maybe throw in a blank every 8 bits for better readability.
# 3  
Old 03-19-2009
nope!!! not home work.
actually i want to convert the 0D (Carriage return ) to binary bits. not to the binary ascii values like ( 00001101) but, to some un readable format. Can you please suggest me how i can get this. I am implemeting some HL7 standard which i don't about this.
# 4  
Old 03-20-2009
You mean, like this?
Code:
int val;
sscanf("0D", "%02x", &val);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Hexdecimal to Decimal in Solaris awk

Hi there, i want to use this Linux-script on a Solaris System to check the fragmentation Level of ZFS-DataSets: #!/bin/sh zdb -ddddd ${1} | awk --non-decimal-data \ ' /Indirect blocks/ { file_number++; next_block = 0; } /L0/ { split($3, fields, ":"); this_block =... (10 Replies)
Discussion started by: Ragesm
10 Replies

2. UNIX for Dummies Questions & Answers

Converting binary file to text file

Hi, Im wondering how I can convert a binary file to a text file? I have ran the following command to output which type of binary file coding it is od -t x1 -c eHat.data0 | head -20 and that gives me the following output; 0000000 5c 00 00 00 cd 06 f2 41 00 00 00 c6 00 00 00 c6 \ \0 \0 \0... (3 Replies)
Discussion started by: dp0b
3 Replies

3. Shell Programming and Scripting

Converting a binary file to ascii and vice versa?

Hi All, I have a binary file which is being exported from a Database, and i need to convert that to ASCII format. How can i achieve that? And this solution should work for any file which is given to us; means they will give different files from different tables. Thanks in advance. (8 Replies)
Discussion started by: baranisachin
8 Replies

4. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

5. UNIX for Dummies Questions & Answers

Converting binary file to readable format in Ksh

In Unix/Ksh, when I try to look inside a file it says that the file may be a binary file and if I want to see it anyway. When i say 'yes', it shows me the content filled with unreadable symbols (looks like binary). Is there a command that I can run from the Unix prompt to convert/translate that... (3 Replies)
Discussion started by: arthurs
3 Replies

6. IP Networking

converting ip addresses to binary

Can someone point me in the right direction? I'm trying to understand how to do this? Also, how to find out what your subnet is??? (6 Replies)
Discussion started by: marchk
6 Replies

7. Linux

Converting source rpm to binary rpm

Hi, I need to install an rpm file,but I only have '.src.rpm' version of it. I want to convert it to a binary rpm. so I tried this rpm --rebuild somethin.src.rpm But I am gettin '--rebuild:Invalid option' as output Is there another way to rebuild source rpm.? Thanks in... (2 Replies)
Discussion started by: eamani_sun
2 Replies

8. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

9. UNIX for Advanced & Expert Users

Converting ASCII to Binary mode

Dear All, Business Users are transfering ( FTP ) a CSV file into the IBM AIX box with transfer mode as ASCII. But I want to convert the CSV file from ASCII mode into binary mode, as my script expects file in binary mode. Is it possible to do through Unix commands? Thanks in Advance, RK (1 Reply)
Discussion started by: srajeshmca
1 Replies

10. Shell Programming and Scripting

unix script for converting a decimal to binary

Could anybody please help me in writing a script in unix for converting a decimal number to binary number. (3 Replies)
Discussion started by: softy
3 Replies
Login or Register to Ask a Question