Sponsored Content
Top Forums UNIX for Dummies Questions & Answers ANSI C, char to hex conversion Post 302242564 by Perderabo on Thursday 2nd of October 2008 08:46:04 AM
Old 10-02-2008
Code:
printf("%02X_",(int)*(buf+c));

Try casting it to unsigned. In an int, the high bit means negative if it is turned on. When you promote a char to a (signed) int, that high bit is extended all the way across to preserve the sign.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hex Conversion

I need to have my scripts import volume groups and mknod devices files. I have most of the script working but the device file needs to be in the format 0x??0000 (where the question marks are my HEX representations of the volume group number. I have the code below and the output it produces which... (2 Replies)
Discussion started by: insania
2 Replies

2. UNIX for Dummies Questions & Answers

File conversion from Unix to ANSI

1. I have a shell script which creates a file using cat command. How can i find what encoding the file follows (e.g. UTF8, ANSI)? 2. I want to convert that file to PC-ANSI format. How can i achieve that? I tried using the echo $LANG command to find the default encoding. It says parameter not... (2 Replies)
Discussion started by: ssmallya
2 Replies

3. UNIX for Dummies Questions & Answers

Conversion from EBCDIC to HEX

Hello, Is there any utility around able to deal with the conversion of some EBCDIC coded string into an hexadecimal value? Thanks (1 Reply)
Discussion started by: Indalecio
1 Replies

4. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

5. Shell Programming and Scripting

Linux to ansi pc conversion

Hi All, I checked the old posts here. But could not find a solution for my question. I have a file created by one application in HP-UX. My client wants it to be converted into ANSI PC version. I have heard about unixtodos and have worked with it also. But I am totally unaware of of this ANSI... (0 Replies)
Discussion started by: Tuxidow
0 Replies

6. Programming

how to use hex escape char with string in C?

I want it to ouput "abcd", but it dosen't. 1 #include<stdio.h> 2 int main() 3 { 4 printf("a\x62cd"); 5 } 6 gcc alarm.c -o alarm alarm.c: In function 'main': alarm.c:4:9: warning: hex escape sequence out of range It seems that the complier joint "cd" as part of... (8 Replies)
Discussion started by: vistastar
8 Replies

7. Shell Programming and Scripting

HEX to DEC Conversion

I'm trying to convert hex to dec and with the help of output i need to do the process. If i execute the below code assetValue=8f assetNavigation=$(echo "ibase=16; "$assetValue"" | bc) echo $assetNavigation i'm getting the error below $ sh script.sh (standard_in) 1: syntax error... (2 Replies)
Discussion started by: Amutha
2 Replies

8. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

9. Shell Programming and Scripting

How add 0 in hex conversion?

Hi, Got the below code in this forum, for i in `cat test`; do printf "%16s\n" $(echo "ibase=10;obase=16;$i" | bc) done Understand, this will not give output with '0'. Need help to get the output with '0'. Regards, Siva (2 Replies)
Discussion started by: ksgnathan
2 Replies

10. Programming

Invalid conversion from char* to char

Pointers are seeming to get the best of me and I get that error in my program. Here is the code #include <stdio.h> #include <stdlib.h> #include <string.h> #define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n" #define REPORTHEADING2 " Name ... (1 Reply)
Discussion started by: Plum
1 Replies
HUMANIZE_NUMBER(9)					   BSD Kernel Developer's Manual					HUMANIZE_NUMBER(9)

NAME
humanize_number, format_bytes -- human readable numbers SYNOPSIS
int humanize_number(char *buf, size_t len, uint64_t number, const char *suffix, int divisor); int format_bytes(char *buf, size_t len, uint64_t number); DESCRIPTION
The humanize_number() function formats the unsigned 64-bit quantity given in number into buf. A space and then suffix is appended to the end. The supplied buf must be at least len bytes long. If the formatted number (including suffix) is too long to fit into buf, humanize_number() divides number by divisor until it will fit. In this case, suffix is prefixed with the appropriate SI designator. Suitable values of divisor are 1024 or 1000 to remain consistent with the common meanings of the SI designator prefixes. The prefixes are: Prefix Description Multiplier k kilo 1024 M mega 1048576 G giga 1073741824 T tera 1099511627776 P peta 1125899906842624 E exa 1152921504606846976 The len argument must be at least 4 plus the length of suffix, in order to ensure a useful result in buf. The format_bytes() function is a front-end to humanize_number(). It calls the latter with a suffix of ``B''. Also, if the suffix in the returned buf would not have a prefix, the suffix is removed. This means that a result of ``100000'' occurs, instead of ``100000 B''. RETURN VALUES
Both functions return the number of characters stored in buf (excluding the terminating NUL) upon success, or -1 upon failure. SEE ALSO
humanize_number(3) HISTORY
These functions first appeared in NetBSD 1.5. BSD
August 7, 2010 BSD
All times are GMT -4. The time now is 03:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy