Questions tagged [bit-representation]
43 questions
2
votes
5 answers
C++ and unsigned types
I'm reading the C++ Primer 5th Edition, and I don't understand the following part:
In an unsigned type, all the bits represent the value. For example, an 8-bit
unsigned char can hold the values from 0 through 255 inclusive.
What does it mean…

Luiz Fernando
- 185
- 7
2
votes
0 answers
BIGNUM in two's complement representation
I have BIGNUM structure from what contains really big positive integer. I'm converting this BIGNUM to array of bytes using BN_bn2bin function:
BIGNUM *bigInteger = ...
BN_bn2bin(bigInteger, bigIntegerBytes);
I noticed that bigIntegerBytes is in…

Sayaki
- 769
- 14
- 36
1
vote
1 answer
Does the standard mandate that the 1-byte storage of a boolean contain only 1 of 2 possible 8-bit values? If so which ones are they?
Related to this and this.
If I define
bool y = true;
bool n = false;
is the bit-wise content of the 1-byte storage of y and n mandated by the standard? If so, which are those two contents? If not, then how is the comparison between bools themselves…

Enlico
- 23,259
- 6
- 48
- 102
1
vote
4 answers
How to strip the trailing zeros from the bit representation of a number
This is the python version of the same C++ question.
Given a number, num, what is the fastest way to strip off the trailing zeros from its binary representation?
For example, let num = 232. We have bin(num) equal to 0b11101000 and we would like to…

joseville
- 685
- 3
- 16
1
vote
1 answer
struct binary representation in c++
This is my code:
#include
//extract i:th bit from val of given addr with &
void extractBit(long long unsigned* ptr,int ith) {
std::cout << (*ptr & (1LLU << ith) ? 1 : 0);
}
template void printlnbits(T v)
{
…

DonaldTrump
- 21
- 2
1
vote
2 answers
Why subtract from 256 when assigning signed char to unsigned char in C++?
in Bjarne's "The C++ Programming Language" book, the following piece of code on chars is given:
signed char sc = -140;
unsigned char uc = sc;
cout << uc // prints 't'
1Q) chars are 1byte (8 bits) in my hardware. what is the binary representation of…

Alparslan
- 35
- 6
1
vote
5 answers
How can one store a uint64_t in an array?
I am trying to store a uint64_t representation of a crc64 checksum as an array.
The checksum will always be like uint64_t res = 0x72e3daa0aa188782, so the I want that to be stored as an array, char digest[8], where digest[0] is 72, digest[1] is…

Jon Weinraub
- 397
- 1
- 8
- 18
1
vote
1 answer
Same function with same inputs returns different values
Lets say I have a function like follows:
testFunction <- function(testInputs){
print( sum(testInputs)+1 == 2 )
return( sum(testInputs) == 1 )
}
When I test this on command line with following input: c(0.65, 0.3, 0.05), it prints and returns…

ozgeneral
- 6,079
- 2
- 30
- 45
1
vote
1 answer
Floating point binary representation
I have a problem understading a floating point representation(Two's placement-sign mantissa exponent), could you check, am I doing right?
-1/7
-1*1/7*2^0=-1*4/7*2^1=-1*4/7*2^2=-1*8/7*2^3
so in binary itd be like:
1 00000011 1.001 001 001 001 001…

A. Martin
- 11
- 4
1
vote
1 answer
Bit representation and meaning of format
I am working on a home assignment and I don't understand one thing about it.. Maybe some of you guys can help me with that.
(a < 0) ? 1 : -1
What does this mean?

drleifz
- 189
- 3
- 12
0
votes
2 answers
How to make a template function in C++ to define a bit representation of any type
template
std::string bit_representation(T &&type) {
uint8_t data[sizeof(T)];
if constexpr (std::is_copy_constructible_v) {
T tmp(type);
std::memcpy(&data, &tmp, sizeof(T));
} else if…

vanyabeat
- 1
- 1
0
votes
0 answers
Reading data from a network connection without making assumptions about bit representation
I want to transfer data from a client to a server. The data is stored in a Data:
class Data{
Type1 Obj1;
Type2 Obj2;
Type3 Obj3;
//...
}
First I insert the data into a buffer type:
Buffer(data);
Then I use one of Boost.Asio's…

Mark Wallace
- 528
- 2
- 12
0
votes
0 answers
long long int bit representation, C++
This is my code:
template void printlnbits(T v) {
const int value_size = sizeof(v) * 8;
long long int* ch = (long long int*)&v;
int j = 0;
for (int i = value_size - 1; i >= 0; --i)
{
extractBit(*ch,…

Leon
- 63
- 7
0
votes
1 answer
ISO Message Representation , Wired behavior in the "pack" method in JPOS
I have 2 web services .. once accepts a payload like this :
{
"MTI": "0100",
"2": "4655206331051889",
"3": "000000",
"4": "000000012300",
"7": "0321054133",
"11": "001205",
"14": "0325",
"18": "5399",
"22":…

Abdelrahman Ashraf
- 57
- 2
- 9
0
votes
2 answers
Can anyone help me with this exercise that i found online but i can't understand why the result is "aaaaaaaa". can you give me a hand?
i found this exercise online but i can't understand why the result is "aaaaaaaa". can you give me a hand ?
#include
void a(char * s) {
while(*s++ != '\0')
printf("a");
}
int main() {
int data[5] = {-1,-3,256,-4,0};
…

lory0312
- 21
- 1