Sponsored Content
Top Forums Shell Programming and Scripting How to get the negate of decimal to binary? Post 302879166 by digiteltlc on Wednesday 11th of December 2013 02:43:05 AM
Old 12-11-2013
How to get the negate of decimal to binary?

Hi All,
New to this forum (and yes , a newbie in programming..Smilie)


I have a decimal to binary converter script done this way :

i=$1

bit0=$(( (i & 0x01) > 0 ))
bit1=$(( (i & 0x02) > 0 ))
bit2=$(( (i & 0x04) > 0 ))
bit3=$(( (i & 0x08) > 0 ))
bit4=$(( (i & 0x10) > 0 ))
bit5=$(( (i & 0x20) > 0 ))
bit6=$(( (i & 0x40) > 0 ))
bit7=$(( (i & 0x80) > 0 ))


Fisrt I would like to understand how the expression $(( (i & 0x01) > 0 )) works

Next, I need to obtain the same bits to its negate, so i.e. if for decimal 177

bit0=1
bit1=0
bit2=0
bit3=0
bit4=1
bit5=1
bit6=0
bit7=1


I need

bit8=0
bit9=1
bitA=1
bitB=1
bitC=0
bitD=0
bitE=1
bitF=0


is there a way to accomplish this inside the same script ??

Thank you very much.
 

9 More Discussions You Might Find Interesting

1. 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

2. Programming

decimal to binary function error

I have the following simple code to return a binary number in a array format given an interger and the number of the bits for specifying the interger as binary number. #include <stdio.h> #include <stdlib.h> int main () { // int* get_binary_number(int* bit_array, int num, int... (8 Replies)
Discussion started by: return_user
8 Replies

3. 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

4. Shell Programming and Scripting

negate search help

Hi, I've tried a lot of negate codes in this forum, but they do not perform what I intended. Please help. inputfile: Paragraph1 contents: die1, die2, die3, pr_name1, pr_name2 pr_name3, pr_name4 Paragraph2 more contents: die1, die2, die3, pr_name1, pr_name2 pr_name3, pr_name4 ... (5 Replies)
Discussion started by: shamushamu
5 Replies

5. UNIX for Dummies Questions & Answers

Decimal to BCD (Binary Coded Decimal)

Anybody please help me... Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary Coded Decimal) representation. Also, draw its Flow Chart. This is a unix qn... plz post algorithm for that :confused: (1 Reply)
Discussion started by: caramba
1 Replies

6. Homework & Coursework Questions

Decimal to BCD (Binary Coded Decimal)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Design an algorithm that accepts an input a decimal number and converts it into BCD (Binary... (2 Replies)
Discussion started by: caramba
2 Replies

7. Programming

Binary to decimal for particular bits

Hello, I have script which work fine on particular data.file . The next feature I want to achieve is to get the decimal equivalent of data to data. The data looks like this : data(01000000000000000000110000000000) thank you.. #include <iostream> #include <fstream> #include... (4 Replies)
Discussion started by: emily
4 Replies

8. Programming

Urgent help needed.. C++ program to convert decimal to hexa decimal

Hi , seq can be 0...128 int windex = seq / 8; int bindex = seq % 8; unsigned char bitvalue = '\x01' << (7-bindex) ; bpv.bitmapvalue = bitvalue; This is the part of a program to convert decimal to bitmap value of hexadecimal. I want this to change to convert only to... (1 Reply)
Discussion started by: greenworld123
1 Replies

9. UNIX for Beginners Questions & Answers

Negative decimal to binary

Is there a fast way to convert a negative decimal value into a signed binary number in bash script ? I've looked a lot on internet but I saw nothing... (For exemple : -1 become 11111111.) (9 Replies)
Discussion started by: Zedki
9 Replies
libcaca attribute definitions(3caca)				      libcaca				      libcaca attribute definitions(3caca)

NAME
libcaca attribute definitions - Enumerations enum caca_color { CACA_BLACK = 0x00, CACA_BLUE = 0x01, CACA_GREEN = 0x02, CACA_CYAN = 0x03, CACA_RED = 0x04, CACA_MAGENTA = 0x05, CACA_BROWN = 0x06, CACA_LIGHTGRAY = 0x07, CACA_DARKGRAY = 0x08, CACA_LIGHTBLUE = 0x09, CACA_LIGHTGREEN = 0x0a, CACA_LIGHTCYAN = 0x0b, CACA_LIGHTRED = 0x0c, CACA_LIGHTMAGENTA = 0x0d, CACA_YELLOW = 0x0e, CACA_WHITE = 0x0f, CACA_DEFAULT = 0x10, CACA_TRANSPARENT = 0x20 } enum caca_style { CACA_BOLD = 0x01, CACA_ITALICS = 0x02, CACA_UNDERLINE = 0x04, CACA_BLINK = 0x08 } Detailed Description Colours and styles that can be used with caca_set_attr(). Enumeration Type Documentation enum caca_color libcaca colour keyword Enumerator: CACA_BLACK The colour index for black. CACA_BLUE The colour index for blue. CACA_GREEN The colour index for green. CACA_CYAN The colour index for cyan. CACA_RED The colour index for red. CACA_MAGENTA The colour index for magenta. CACA_BROWN The colour index for brown. CACA_LIGHTGRAY The colour index for light gray. CACA_DARKGRAY The colour index for dark gray. CACA_LIGHTBLUE The colour index for blue. CACA_LIGHTGREEN The colour index for light green. CACA_LIGHTCYAN The colour index for light cyan. CACA_LIGHTRED The colour index for light red. CACA_LIGHTMAGENTA The colour index for light magenta. CACA_YELLOW The colour index for yellow. CACA_WHITE The colour index for white. CACA_DEFAULT The output driver's default colour. CACA_TRANSPARENT The transparent colour. enum caca_style libcaca style keyword Enumerator: CACA_BOLD The style mask for bold. CACA_ITALICS The style mask for italics. CACA_UNDERLINE The style mask for underline. CACA_BLINK The style mask for blink. Author Generated automatically by Doxygen for libcaca from the source code. Version 0.99.beta18 Fri Apr 6 2012 libcaca attribute definitions(3caca)
All times are GMT -4. The time now is 11:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy