Sponsored Content
Top Forums Programming Signed and unsigned intergers Post 302716731 by Corona688 on Tuesday 16th of October 2012 11:04:33 PM
Old 10-17-2012
The difference between signed and unsigned isn't the minus symbol, it's how the numbers are interpreted by the processor.

An unsigned signed 8-bit number:
Code:
binary 1 1 1 1 1 1 1 1 = 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0 = 255

A signed 8-bit number:
Code:
binary 1 1 1 1 1 1 1 1 = (-2^7) + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0 = -1

This allows easy subtraction as well as addition through two's-complement arithmetic -- add the opposite plus one to subract.
 

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. UNIX for Dummies Questions & Answers

So, like, I signed on with a new hosting company...

... and there was absolutely nothing installed except fedora and ssh. I used yum to install vsftp and httpd, both start and ps shows they're running, and yet I can't connect with either of them. Where on earth or in redhat do I begin looking to unravel this one? I've overseen a server before but... (3 Replies)
Discussion started by: Bobby
3 Replies

4. Red Hat

cast from const void* to unsigned int loses precision

Hello everey one, here i am attempting to compile a c++ project .it's throughing the following errors. my machine details are as follows: Linux chmclozr0119 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux errors: ===== Generating... (0 Replies)
Discussion started by: mannam srinivas
0 Replies

5. Shell Programming and Scripting

add signed and unsigned numbers- awk help

Hi All, I have written the below to add the numbers in a column. Postive numbers are unsigned and negative numbers are signed in the file. After the below cmd I am getting -0.00 , instead of 0.00. Can someone guide me on what I am missing in the cmd. grep '^L' $FileName| awk -F"|" ' {... (7 Replies)
Discussion started by: gsjdrr
7 Replies

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

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

8. Programming

Comparing unsigned char bits.

/******************************************************************************/ /* Printing an unsigned character in bits */ #include <stdio.h> void display_bits ( unsigned char ); int main() { unsigned char x; /*... (15 Replies)
Discussion started by: robin_simple
15 Replies

9. Programming

Unable to assign zero to unsigned character array

Hi, I am unable to assign value zero to my variable which is defined as unsigned char. typedef struct ABCD { unsigned char abc; unsigned char def; unsigned char ghi; } ABCD; typedef ABCD *PABCD; In my Por*C code, i assign the values using memcpy like below ... (3 Replies)
Discussion started by: gthangav
3 Replies

10. 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
STDINT(3)						   BSD Library Functions Manual 						 STDINT(3)

NAME
stdint -- standard integer types SYNOPSIS
#include <stdint.h> DESCRIPTION
The <stdint.h> header provides source-portable integer types of a specific size, smallest memory footprint with a minimum size, fastest access speed with a minimum size, largest integer size, and those capable of storing pointers. The types int8_t, int16_t, int32_t, and int64_t provide a signed integer type of width 8, 16, 32, or 64 bits, respectively. The types uint8_t, uint16_t, uint32_t, and uint64_t provide an unsigned integer type of width 8, 16, 32, or 64 bits, respectively. These integer types should be used when a specific size is required. The types int_fast8_t, int_fast16_t, int_fast32_t, and int_fast64_t provide the fastest signed integer type with a width of at least 8, 16, 32, or 64 bits, respectively. The types uint_fast8_t, uint_fast16_t, uint_fast32_t, and uint_fast64_t provide the fastest unsigned integer type with a width of at least 8, 16, 32, or 64 bits, respectively. These types should be used when access speed is paramount, and when a specific size is not required. The types int_least8_t, int_least16_t, int_least32_t, and int_least64_t provide the smallest memory footprint signed integer type with a width of at least 8, 16, 32, or 64 bits, respectively. The types uint_least8_t, uint_least16_t, uint_least32_t, and uint_least64_t provide the smallest memory footprint unsigned integer type with a width of at least 8, 16, 32, or 64 bits, respectively. These types should be used when memory storage is of concern, and when a specific size is not required. The type intmax_t provides a signed integer type large enough to hold any other signed integer. The type uintmax_t provides an unsigned integer type large enough to hold any other unsigned integer. These types are generally the largest signed and unsigned integer types avail- able on a specific architecture. The type intptr_t provides a signed integer type with the ability to hold a pointer to void, that can later be converted back to a pointer to void. The type uintptr_t provides an unsigned integer type with the ability to hold a pointer to void, that can later be converted back to a pointer to void. SEE ALSO
inttypes(3), limits(3), stdbool(3), unistd(3) STANDARDS
The <stdint.h> header conforms to ISO/IEC 9899:1999 (``ISO C99'') and IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The <stdint.h> header was first introduced in NetBSD 1.6. BSD
August 9, 2011 BSD
All times are GMT -4. The time now is 09:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy