Questions tagged [unsigned-integer]
A specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number.
558
questions
0
votes
2
answers
60
views
How to convert a char to signed integer in python
I don't have much experience with Python, so I need your help!
In the following example I can convert a char to unsigned integer, but i need a signed integer. How can I convert a char to signed ...
-1
votes
1
answer
46
views
How to subtract negative numbers from negative numbers using Complement notation?
I've just started learning. I am trying to understand this thoroughly and deeply. I somewhat understand it as long as it's subtraction between a Smaller number from a Larger number or a Larger number ...
0
votes
1
answer
68
views
Does compound assignment of two unsigned integers of the same type always operate as if using that type's modular arithmetic?
Here is a conjecture:
For expression a op b where a and b are of the same unsigned integral type U, and op is one of the compound assignment operators (+=,-=,*=,/=,%=,&=,|=,^=,<<=,>>=),...
0
votes
1
answer
33
views
How to Get only numeric value in text file using powershell?
I have a text file sample.txt containing
computer
computer.pc = 1
pc
i want only number 1, where i want to assign that value to a variable
$number = Get -content "sample.txt"
2
votes
3
answers
34
views
Program printing incorrect symbolic constants values
I am currently learning C and I am attempting to complete the K&R exercise 2-1. (Write a program to determine the ranges of char, short, int, and long variables, both
signed and unsigned, by ...
0
votes
1
answer
53
views
reading and printing unsigned int from file
I am trying to print and read unsigned ints from a .txt file. I am using fprintf to print the unsigend int, (menualy checking the file presents the wanted values), but when reading it, I get a weird ...
0
votes
1
answer
51
views
Using unsigned int as array index could lead to buffer overflows?
I have this code in which I have to find security vulnerabilities.
win() {
printf("Congratulations!");
}
setter(unsigned int i, int v, int * a) {
a[i] = v;
}
main() {
int i, v;
...
0
votes
0
answers
155
views
Splitting bytes into "16 bit words"
I have the following task:
Write a function split(data: bytes) -> List[int] that splits the input
from data into 16 bit long segments, each represented as an
unsigned integer. These integers should ...
0
votes
0
answers
45
views
Which C/C++ data type should I use for PHI(N) calculator?
I found a source code online for calculating PHI.
I made some small adjustments to the variable types, such as using an unsigned long int, however I am limited to input numbers that are too small for ...
1
vote
6
answers
146
views
storing digits of a number in array
How do I store different digits of an integer in any array
like 1234 to {1,2,3,4}
It can be done using char str[]="1234"; printf("%c",str[0];
but how to do it without using string ...
-1
votes
1
answer
55
views
Turning an unsigned integer into a double from 0 to 1. Dividing by integer limit not working [duplicate]
So I'm wanting to turn an unsigned integer (Fairly large one, often above half of the unsigned integer limit) into a double that shows how far it is between 0 and the unsigned integer limit. Problem ...
0
votes
2
answers
138
views
About int and unsigned int
There are the following programs:
#include <stdio.h>
int main(void)
{
int i=2147483647;
unsigned int j=4294967295;
printf("%d %d %d\n",i,i+1,i+2);
printf("%u %u %u\n&...
0
votes
0
answers
60
views
Is taking uint8 from user's input more efficient than taking uint64?
The following code takes a 64-bit unsigned integer from it's user's input:
package main
import (
"fmt"
"bufio"
"os"
"strconv"
)
func main() {
...
2
votes
2
answers
66
views
va_args not accepting signed integer in C
I was designing my kernel using C. While making the kprintf function (a function like printf but works with the kernel) I saw that signed integers (precisely the data type is long), va_args is ...
0
votes
2
answers
29
views
"Pack" a np.array of 4 np.uint16 into a single np.unit64
Given a np.array of 4 np.uint16
input = np.random.randint(10, size=4, dtype=np.uint16)
how can I "pack" their binary representations into a single np.uint64?
# Example of C code
# output = ...
-1
votes
1
answer
52
views
How to handle overflow of unsigned int in C? [closed]
How can I change line 6 to handle the integer overflow so that this code will never terminate (while still increasing i in each loop iteration)?
1 int main() {
2 unsigned int i;
3 i = 1;
4 ...
0
votes
0
answers
125
views
How to store unsigned int value to unsigned char variable?
Suppose I have
unsigned int x = 0x12a
unsigned char y = 0x000
How can I make x = y? When I try to assign x to y, i get y = 0x02a
0
votes
2
answers
60
views
C usual arithmetic conversions rules
... the integer promotions are performed on both operands.
Then the following rules are applied to the promoted operands:
If both operands have the same type, then no further conversion is needed.
...
1
vote
0
answers
42
views
Passing parameters from c++ to c# as call back
I have a c++ and c# application talking to each other.
The way I have set things up is as follows:
the c++ project is referred to in the c# project as follows
Now it does various things which are not ...
4
votes
3
answers
116
views
Why do `(char)~0` and `(unsigned char)~0` return values of different widths?
I bumped into this while writing a program trying to print the constituent byte values of UTF-8 characters.
This is the program that I wrote to test the various ~0 operations:
#include <stdio.h>
...
-1
votes
1
answer
65
views
How to find the mean and the variance in assembly from an unsigned integer into a floating-point number/decimal
Here is the code that I have below:
INCLUDE Irvine32.inc
.386
.model flat, stdcall
.stack 4096
ExitProcess proto, dwExitCode:dword
PWORD TYPEDEF PTR WORD
.data
RAW WORD 10, 12 , 8, 17, 9, 22, 18, ...
0
votes
2
answers
507
views
Converting unsigned to signed integers (Using Excel formulas or Power Query)
I have a list of unsigned 32-bit unsigned integers that actually are supposed to represent 32-bit signed integers.
For example 62714 = binary 1111010011111010 = signed -2822 when interpreted as two's ...
0
votes
0
answers
19
views
Can unsigned int variable hold negative value?
#include<stdio.h>
int main()
{
signed int a=-1;
unsigned int b=-1;
if(a==b)
printf("%d %d",a,b);
else
...
0
votes
1
answer
256
views
Calculate time difference in C++(hours, minutes, seconds) with type unsigned int
For one of my college classes using C++, we have to implement a class that creates time objects and that can do different arithmetic functions (+, -, -=, +=, etc...) between two different times.
My ...
0
votes
1
answer
71
views
c programming how do i read the bytes stored as little indian?
unsigned short num = 258;
//How can i read the byte value as on how this num 258 is getting store (by default is stored as litle indian right?) so the value should be something like this [ 2, 1 ]or [...
5
votes
2
answers
255
views
Difference between uint can be negative
I have a question about unsigned integer in C/C++. They and the results of operations on them should always be positive or equal to zero but it does not look the case with uint16_t difference. uint ...
0
votes
0
answers
87
views
Increasing precision for decimal part from 8 decimals to 18 decimals using Uint 128 bit
I am trying to write the translation of unsigned integers to floating points with precision of up to 18 decimals.
The language (Clarity) that I am using doesn't have floating points in it so I have to ...
5
votes
1
answer
244
views
Dealing with unsigned integers
I know that unsigned integers are infamous and generally avoided by C++ devs. I have a class with two int member variables that should not contain negative values:
.
.
.
private:
int m_Y_AxisLen;
...
2
votes
3
answers
401
views
How to efficiently count leading zeros in a 24 bit unsigned integer?
Most of the clz() (SW impl.) are optimized for 32 bit unsigned integer.
How to efficiently count leading zeros in a 24 bit unsigned integer?
UPD. Target's characteristics:
CHAR_BIT 24
...
0
votes
0
answers
56
views
C++: Unsigned integer underflow optimization
I'm having some problem with the following issue in c++:
#include <iostream>
using namespace std;
int main()
{
uint8_t l = 200, r = 2, c = 199;
bool res1 = (l - c) < (r - c);
...
1
vote
1
answer
69
views
Why g++ O2 option make unsigned wrap around not working?
I was trying to write a queue with c++, and I learn from intel dpdk libring that I can do that by writing codes like that using the unsigned wrap around property:
#include <cstdio>
#include <...
2
votes
1
answer
77
views
Is it possible to get the unsigned integer quotient and remained at once in C?
I am aware of this question about getting the quotient and remainder in a single operation in C. However the C div and ldiv functions take int and long arguments. But how can I perform unsigned ...
1
vote
1
answer
334
views
How to convert unsigned char to unsigned int in c++?
I have the following piece of code:
const unsigned char *a = (const unsigned char *) input_items;
input_items is basically the contents of a binary file.
Now a[0] = 7, and i want to convert this ...
1
vote
2
answers
199
views
uint32_t is having a negative value when MSB is 1
I need to make a signed value into an unsigned value and while trying to get this to work I found uint32_t is somehow signed when i assign the MSB to 1.
In this code i show what i mean. Test1/2 are to ...
0
votes
1
answer
170
views
Unsigned short int to Binary in C without using malloc() function?
I wrote a program that changes an unsigned int to into binary. In my function I use the malloc() function. I was wondering if there was a way to do it without the malloc().
#include <stdio.h>
#...
0
votes
1
answer
35
views
`using my_type = unsigned;` vs `using my_type = unsigned int;` in C++
In C++, are the following two code snippets equivalent?
using my_type = unsigned;
my_type variable;
and
using my_type = unsigned int;
my_type variable;
If they are, why bother ...
2
votes
3
answers
364
views
Find the position of a max on a number
I have C program that needs to find the position of a number. It goes like this:
From standard input we enter unknown number of number that are positive. The numbers have maximum of 5 digits, we read ...
2
votes
0
answers
75
views
Is right shifting unsigned types in c++ implementation defined
I know that right shifting a signed type in c++ (such as an int) is implementation defined: some machines will perform a logical right shift, and other machines will perform an arithmetic right shift.
...
-1
votes
2
answers
52
views
Why wont my C code about reversed bits work?
I am working on code to reverse an unsigned int whose bits are the same but in reverse order. My code wont stop running while taking user input. What am I doing wrong?
#include <stdio.h>
...
1
vote
1
answer
88
views
assigning an unsigned value to integer data type
I wrote code:
int a = -1U;
cout << a;
Why the output is -1 not 2^w-1?
As in the case of:
long long a = -1U;
cout << a;
The output comes out as
4294967295
-1
votes
1
answer
60
views
Unsigned integer notation in C [closed]
I have written some code but I keep getting this error and I am unsure on how to fix this issue.
hw6.c:14:13: warning: data argument not used by format string [-Wformat-extra-args]
scanf("...
0
votes
0
answers
78
views
How to send unsigned integer to BLE device from Android Device?
I am developing app which sets time on the BLE device. For that to work I need to send array of values bigger that 127 (Values like 239,254, etc). But BLE setting value for characteristics supports ...
0
votes
3
answers
370
views
Printf in unsigned short int and unsigned int using %d
Why in second printf when using %d I am not getting -1?
#include<stdio.h>
int main(){
unsigned int u=-1;
unsigned short int y=-1;
printf("%d %u\n",u,u);
printf("%d ...
2
votes
2
answers
93
views
С typecasting in conditions
There is a simple example:
unsigned a = -5;
int b = 5;
if (a + b <= -1){
...
}
To which type will cast a+b? To signed or unsigned? And is it noted in C-standard or compiler will decide what to do?
0
votes
2
answers
193
views
Unsigned modulo in Java
I'm porting some c code which is doing a modulo on an uint32_t. An uint32_t fits in a Java int bit-wise, but I cannot figure out how to perform a modulo operation on it without converting to a long. ...
0
votes
0
answers
36
views
Infinite loop Vs. A loop that overflows?
I'm learning about signed vs. unsigned types in Java and came across a tricky example question that has me puzzled:
Is the following code an infinite loop? Why or why not?
for(long x = 0; x != -1; x++...
2
votes
2
answers
86
views
Why the comparison result are not as expected?
Could you explain why the following code give these result?
#include <iostream>
int main()
{
int x = -1;
unsigned int y = 1;
if (x > y)
std::cout << "true";...
0
votes
0
answers
29
views
how c++ handles the arithmetic between an int and an unsigned int? [duplicate]
I am a beginner in cpp, reading about the topic Type-conversions. I want to ask how cpp handles the arithmetic between an int and an unsigned int inernally to calculate the result?
For example, ...
1
vote
1
answer
159
views
Why does storing an 32-bit unsigned int value of -1 in SQLite DB and reading it back result in the value getting changed to half?
In its simplest form, below is a pseudo code of the problem:
enum E { VALUE = -1; }
uint32_t value = VALUE; // signed to unsigned conversion without typecasting
SQLiteDB.INSERT(<table containing `...
0
votes
0
answers
48
views
How to solve this pointer error? (from incompatible pointer type)
I've this function:(myvariable is un unsigned int)
config_setting_lookup_int64 is the libconfig.h function -> int config_lookup_int64 (const config t * config, [Function]
const char * path, long ...