Sponsored Content
Top Forums Shell Programming and Scripting add signed and unsigned numbers- awk help Post 302428657 by radoulov on Thursday 10th of June 2010 12:01:51 PM
Old 06-10-2010
Try with nawk or /usr/xpg4/bin/awk.
 

10 More Discussions You Might Find Interesting

1. Programming

Unsigned int

How can I store and/or print() a number that is larger than 4 294 967 295 in C? is int64_t or u_int64_t what I need ? if, so how can I printf it to stdout? (2 Replies)
Discussion started by: nimnod
2 Replies

2. Programming

to get the correct value with unsigned int

hi, Please help me with the following code to get the difference in values. struct a{ int b1; int c1; char d1; } main() { unsigned int b=10; unsigned int c; c = b - (unsigned int )sizeof(a); printf("%d",c); } Here c returns some junk value. How can i get the... (2 Replies)
Discussion started by: naan
2 Replies

3. Shell Programming and Scripting

Using Awk to Add Numbers

echo "0.1 2.0 0.4 2.0 4.3 1.0 6.0 9.0" | awk 'BEGIN {total=0} {total += $1} END {print total}' I want to add the above output from the echo command, but i can't figure this out. The output above always spits out inaccurate numbers. can someone please provide me with a one liner similar to... (4 Replies)
Discussion started by: SkySmart
4 Replies

4. UNIX for Advanced & Expert Users

"Signed Linux" - Only executing signed programs

Hey folks, not sure whether this or the security board is the right forum. If I failed, please move :) So here's the problem: I need to build a Linux environment in which only "signed" processes are allowed to run. When I say signed I don't mean a VeriSign signature like you know it from... (5 Replies)
Discussion started by: disaster
5 Replies

5. Programming

Help with understanding ( int, char, long, short, signed, unsigned etc.... )

My question is simple: When should I use a long, int, char, unsigned/signed variables?? When I declare a variable "unsigned;" what did I do it??? Why would I delcare an integer "long" or "short" ( unsigned or signed)?? Any examples of when things like "unsigned", "long", "short" etc...... (6 Replies)
Discussion started by: cpp_beginner
6 Replies

6. Programming

[ASM] Adding SIGNED numbers?

Hi guys, I want to add a list of SIGNED numbers... but I don't know how to tell the computer to ADD THEM as signed, let me explain further: when adding 200 + (-100) , it becomes 100, but in asm the computer always add them as unsigned, so I always get the 300. Do I have to add them in a... (4 Replies)
Discussion started by: lamachejo
4 Replies

7. Programming

Signed and unsigned intergers

when a date type is considered signed and unsigned is that simple referring to - for signed and positive numbers for unsigned? Further if that is the case would mutiplying and dividing ect where 2 signed numbers, like (-2)*(-2) = 4 result in a unsigned. (3 Replies)
Discussion started by: Fingerz
3 Replies

8. UNIX for Dummies Questions & Answers

[Solved] awk solution to add sequential numbers based on a word

Hi experts, I've been struggling to format a large genetic dataset. It's complicated to explain so I'll simply post example input/output $cat input.txt ID GENE pos start end blah1 coolgene 1 3 5 blah2 coolgene 1 4 6 blah3 coolgene 1 4 ... (4 Replies)
Discussion started by: torchij
4 Replies

9. OS X (Apple)

Unsigned to signed, error?...

Hi guys... Macbook Pro, 13", circa August 2012, OSX 10.7.5, default bash terminal. I require the capability to convert +32767 to -32768 into signed hex words... The example piece code below works perfectly except... #/bin/bash # sign.sh # Unsign to sign... while true do # I have used... (2 Replies)
Discussion started by: wisecracker
2 Replies

10. Shell Programming and Scripting

Efficient awk way to add numbers in line fields

data.now: blah1,dah,blaha,sweet,games.log,5297484456,nagios-toin,529748456,on__host=93 SERVICE__ALERT_=51 Warning___The__results__of__service=16 Warning___on__host=92 Auto_save__of__retention__data__completed=1 Warning___Return=68 PASSIVE__SERVICE__CHECK_=53 ,1026--1313,1... (12 Replies)
Discussion started by: SkySmart
12 Replies
PACK(3) 								 1								   PACK(3)

pack - Pack data into binary string

SYNOPSIS
string pack (string $format, [mixed $args], [mixed $...]) DESCRIPTION
Pack given arguments into a binary string according to $format. The idea for this function was taken from Perl and all formatting codes work the same as in Perl. However, there are some formatting codes that are missing such as Perl's "u" format code. Note that the distinction between signed and unsigned values only affects the function unpack(3), where as function pack(3) gives the same result for signed and unsigned format codes. PARAMETERS
o $format - The $format string consists of format codes followed by an optional repeater argument. The repeater argument can be either an integer value or * for repeating to the end of the input data. For a, A, h, H the repeat count specifies how many characters of one data argument are taken, for @ it is the absolute position where to put the next data, for everything else the repeat count specifies how many data arguments are consumed and packed into the resulting binary string. Currently implemented formats are: pack(3) format characters +-----+---------------------------------------------------+ |Code | | | | | | | Description | | | | +-----+---------------------------------------------------+ | a | | | | | | | NUL-padded string | | | | | A | | | | | | | SPACE-padded string | | | | | h | | | | | | | Hex string, low nibble first | | | | | H | | | | | | | Hex string, high nibble first | | | | | c | | | | | | | signed char | | | | | C | | | | | | | unsigned char | | | | | s | | | | | | | signed short (always 16 bit, machine byte order) | | | | | S | | | | | | | unsigned short (always 16 bit, machine byte | | | order) | | | | | n | | | | | | | unsigned short (always 16 bit, big endian byte | | | order) | | | | | v | | | | | | | unsigned short (always 16 bit, little endian byte | | | order) | | | | | i | | | | | | | signed integer (machine dependent size and byte | | | order) | | | | | I | | | | | | | unsigned integer (machine dependent size and byte | | | order) | | | | | l | | | | | | | signed long (always 32 bit, machine byte order) | | | | | L | | | | | | | unsigned long (always 32 bit, machine byte order) | | | | | N | | | | | | | unsigned long (always 32 bit, big endian byte | | | order) | | | | | V | | | | | | | unsigned long (always 32 bit, little endian byte | | | order) | | | | | q | | | | | | | signed long long (always 64 bit, machine byte | | | order) | | | | | Q | | | | | | | unsigned long long (always 64 bit, machine byte | | | order) | | | | | J | | | | | | | unsigned long long (always 64 bit, big endian | | | byte order) | | | | | P | | | | | | | unsigned long long (always 64 bit, little endian | | | byte order) | | | | | f | | | | | | | float (machine dependent size and representation) | | | | | d | | | | | | | double (machine dependent size and representa- | | | tion) | | | | | x | | | | | | | NUL byte | | | | | X | | | | | | | Back up one byte | | | | | Z | | | | | | | NUL-padded string (new in PHP 5.5) | | | | | @ | | | | | | | NUL-fill to absolute position | | | | +-----+---------------------------------------------------+ o $args - RETURN VALUES
Returns a binary string containing data. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.3 | | | | | | | The "q", "Q", "J" and "P" codes were added to | | | enable working with 64-bit numbers. | | | | | 5.5.0 | | | | | | | The "Z" code was added with equivalent function- | | | ality to "a" for Perl compatibility. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 pack(3) example <?php $binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66); ?> The resulting binary string will be 6 bytes long and contain the byte sequence 0x12, 0x34, 0x78, 0x56, 0x41, 0x42. NOTES
Caution Note that PHP internally stores integer values as signed values of a machine-dependent size (C type long). Integer literals and operations that yield numbers outside the bounds of the integer type will be stored as float. When packing these floats as integers, they are first cast into the integer type. This may or may not result in the desired byte pattern. The most relevant case is when packing unsigned numbers that would be representable with the integer type if it were unsigned. In systems where the integer type has a 32-bit size, the cast usually results in the same byte pattern as if the integer were unsigned (although this relies on implementation-defined unsigned to signed conversions, as per the C standard). In systems where the integer type has 64-bit size, the float most likely does not have a mantissa large enough to hold the value without loss of precision. If those systems also have a native 64-bit C int type (most UNIX-like systems don't), the only way to use the I pack format in the upper range is to create integer negative values with the same byte representation as the desired unsigned value. SEE ALSO
unpack(3). PHP Documentation Group PACK(3)
All times are GMT -4. The time now is 01:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy