05-16-2007
If the course says that ((~ 2#1001)) evaluates to 2#110, I wonder what shell they were using. With ksh I get:
$ typeset -i2 b
$ echo $((2#1001)) $((b=~2#1001)) $b
9 -10 -2#1010
With bash, there is no -i2 and I don't see an easy way to get binary output. I could code my own routine, but then the behavior would be whatever I decided. (But I get the "9 -10" part with bash.) Since ksh alone has a way to output binary, I did a few experiments with it. A negative number has many leading 1's while a non-negative has many leading zeros. ksh uses enough positions to output the the leftmost bit transistion. If you exceed the shell's integer size, you get undefined results, but clamping at positive or negative "infinity" (max/min integer) is common with both ksh and bash. The shells I checked have either 32 or 64 bit integers.
9 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
can anybody write a program to divide a number by another number using bitwise operators (9 Replies)
Discussion started by: areef4u
9 Replies
2. Shell Programming and Scripting
Guys,
Pl suggest me how to ignore a path in find command... I am aware of using "!" for other option... but how can i use it like this exampl...
I want to search something for in / but not in
Pl help.
Thanks.. (2 Replies)
Discussion started by: clx
2 Replies
3. Programming
Hi
Suppose we have these code lines:
#define _IN_USE 0x001 /* set when process slot is in use */
#define _EXITING 0x002 /* set when exit is expected */
#define _REFRESHING 0x004
...
1 main () {
2
3 unsigned r_flags =_REFRESHING;
4
5 if (r_flag &... (3 Replies)
Discussion started by: Puntino
3 Replies
4. Shell Programming and Scripting
Hi all,
I've been searching the internet and can't find an answer to this. Im trying to figure out how to negate a whole expression befor an if. I'll explain below.
Let's say
x=0
y=1
] (this is false) I would like to negate this whole boolean condition. To negate the above... (4 Replies)
Discussion started by: rethymno19
4 Replies
5. Homework & Coursework Questions
Hello, have anybody any idea, how to negate some expression?
I have code that greps somethnig and I want filter from it some results...How to make it?
IDontWantThisExpression=$1
grep 'some regex' | grep '$IDontWantThisExpression' testfile.txt
Thanks for any advices.
Faculty of... (2 Replies)
Discussion started by: Dworza
2 Replies
6. FAQ Submission Queue
The purpose of this article is revealing the unrevealed parts of the bitwise XOR.
As we aware, the truth table for the XOR operator is :
A B A^B
0 0 0
0 1 1
1 0 1
1 1 0
For example , 1^2 will be calculated as given below:
First the operands... (1 Reply)
Discussion started by: pandeesh
1 Replies
7. Shell Programming and Scripting
please any one can suggest me how to use bitesie || opearator to do this
#initallize a=0 b=0
#condition
if then
a=0
else a=1
fi
#bitwise or opeartion b = a || b
Please view this code tag video for how to use code tags when posting code and data. (3 Replies)
Discussion started by: Palaniappan
3 Replies
8. Shell Programming and Scripting
Hello,
I want to compute the bitwise number of matches in pairwise fashion for all columns. The problem is I have 18486955 rows and 750 columns. Please help with code, I believe this will take a lot of time, is there a way of tracking progress?
Input
Org1 Org2 Org3
A A T
A ... (9 Replies)
Discussion started by: ritakadm
9 Replies
9. Shell Programming and Scripting
$ ls -1
a.1
b.1
x_a.1
x_b.1
$ ls -1 *
b.1
x_a.1
x_b.1
$ ls -1 **
a.1
b.1
x_a.1
x_b.1The last result is not as expected.
Why?
Thanks. (2 Replies)
Discussion started by: carloszhang
2 Replies
suspend(1) User Commands suspend(1)
NAME
suspend - shell built-in function to halt the current shell
SYNOPSIS
sh
suspend
csh
suspend
ksh
suspend
DESCRIPTION
sh
Stops the execution of the current shell (but not if it is the login shell).
csh
Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su.
ksh
Stops the execution of the current shell (but not if it is the login shell).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5)
SunOS 5.10 15 Apr 1994 suspend(1)