473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to convert 'long' to four bytes in Bourne shell

1
Dear All,

Is there a way to convert long decimal int value to 4-bytes, using Bourne Shell or any commands from minimal Linux (sed, awk, etc)?
The goal is to calculate size of file and place the 4-byte value before it. I.e:

#!/bin/sh
size=`du filename`
cat <convert $size to 4 bytes> filename >filename

Appreciate your help.

UPD: i have found a part of solution:

n = 12345 # sample long int file size
"let n0 = $n % 256"
"let n = $n / 256"
"let n1 = $n % 256"
"let n = $n / 256"
"let n2 = $n % 256"
"let n = $n / 256"
"let n3 = $n % 256"
echo $n0 $n1 $n2 $n3

So now I have these 4 ints representing bytes. The remaining questions is how to write it as 4 bytes to file?
Sep 8 '11 #1
1 2962
sicarie
4,677 Expert Mod 4TB
The size of a long int will depend on several different things.

I would recommend checking the size of your long ints, it may already be 4 bytes.
Sep 8 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: William S. Huizinga | last post by:
I've got an array.array of unsigned char and would like to make a slice of that array (e.g. a) become one long like I would in "C" : l = ((unsigned long *) (&a)); I have been getting what I...
2
by: biner | last post by:
Hello, I have file called PARAMETRES that is used in bourne shell script to define variable. In order to do so I put a ". PARAMETRES" line and the script has acces to all the variable defined in...
1
by: Fred | last post by:
Hi all, I have a nice problem. I´m trying to convert a Long to varchar2. It works when the long field doesn´t contain more than 2000 characters. How do I solve this? I´m working with Oracle 7...
5
by: babylon | last post by:
I can't find any functions in system.convert to convert a 4-byte integer to 4 bytes array... pls help
1
by: les | last post by:
If all are unsigned integers, then why not make it easy on yourself and just multiply each by a scaler to effect the shift? ie each position is just multiplied by 128^n-1 byte1 + byte2*128 +...
6
by: lovecreatesbeauty | last post by:
/* It seems that when an int with width of four bytes is assigned to a one byte width char, the first three bytes from left to right are discarded and the rightest byte is assigned to that char....
7
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
1
by: nanosuna | last post by:
Hi, I was given a task to translate a unix bourne shell script that does file renaming and string replacement on a server . I am not too familiar with the capabilites of JavaScript, so I was...
1
by: =?big5?B?qM6nuw==?= | last post by:
I already knew how to convert bytes to Double, use BitConverter.ToDouble(). but, How to convert double to bytes? for example: double a = 3,444; I want convert to bytes={ ?, ?, ?, ?, ?, ?,...
2
crystal2005
by: crystal2005 | last post by:
Hi all, I have been googling to search an example code of archiving (E.g. .tgz .tar .zip) for my research. However, unluckily i found none. Is there anyone can help to find one? Oh yeah, I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.